2017-10-06 41 views
0

我的表格有滚动问题。当我向下滚动桌子时,我在桌子上方的一个按钮保持在同一位置,保持可见状态,我需要的是当我向下滚动桌子时按钮将消失。自定义表视图的滚动视图

这是我的代码:

@implementation Mis_Servicios 


- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self SetTopBarStyle]; 
    self.title = @"Mis servicios"; 
    barButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"Editar" 
                   style:UIBarButtonItemStylePlain 
                    target:self 
                    action:@selector(toggleEdit)]; 
    self.navigationItem.rightBarButtonItem = barButtonItem; 

    #pragma mark - Table view data source 

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 

     Cell_Detalles *cell = nil; 
     static NSString *CellIdentifier = @"Cell_registro"; 
     cell =(Cell_Detalles *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"Cell_Detalles_7" owner:self options:nil]; 
     cell = (Cell_Detalles *)[nib objectAtIndex:0]; 

     cell.bt_preguntas.layer.cornerRadius = 20; 
     cell.bt_preguntas.backgroundColor = UIColorFromRGB(0x259026); 
     [cell.bt_preguntas setTitle:@"Alta de servicios" forState:UIControlStateNormal]; 
     [cell.bt_preguntas setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
     [cell.bt_preguntas addTarget:self action:@selector(goAltas) forControlEvents:UIControlEventTouchUpInside]; 

     return cell; 
    } 

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView 
    { 
     NSLog(@"%f/%f",self.tableView.contentOffset.y, self.tableView.contentSize.height - self.tableView.frame.size.height); 

     if (self.tableView.contentOffset.y == self.tableView.contentSize.height - self.tableView.frame.size.height){ 
      if (pagenumber < pages) { 
       ++pagenumber; 
       [self ObtenerDatos]; 
      } 

     } 

    } 

这是表上面的按钮:[cell.bt_preguntas的setTitle:@ “阿尔塔德SERVICIOS” forState:UIControlStateNormal];

这是一个如何显示这个画面的图像,我使用了Storyboard和Xib的表格。

enter image description here

回答

1

这部分标题上一个普通样式表视图是如何工作的。请参阅电话应用程序的“联系人”选项卡以获取一个很好的示例

如果您只有一个按钮,并且您希望它位于表格视图的顶部,并且希望它在滚动表格视图时滚动,那么您应该将按钮视图设置为表格,而不是实施viewForHeaderInSection查看tableHeaderView

下面的代码添加到您的viewDidLoad方法:

NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"Cell_Detalles_7" owner:self options:nil]; 
Cell_Detalles *cell = (Cell_Detalles *)[nib objectAtIndex:0]; 

cell.bt_preguntas.layer.cornerRadius = 20; 
cell.bt_preguntas.backgroundColor = UIColorFromRGB(0x259026); 
[cell.bt_preguntas setTitle:@"Alta de servicios" forState:UIControlStateNormal]; 
[cell.bt_preguntas setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[cell.bt_preguntas addTarget:self action:@selector(goAltas) forControlEvents:UIControlEventTouchUpInside]; 

self.tableView.tableHeaderView = cell; 

,并删除你的整个viewForHeaderInSection方法。

+0

你能给我举个例子吗?对不起,但我是目标C的新手,我从来没有这样做过。 –

+1

查看我更新的答案。 – rmaddy

+0

非常感谢,这解决了我的问题! –