Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewcontentInset:将表格滚动到顶部时,第一个标题上方的行仍然可见_Ios_Objective C_Uitableview_Cocoa Touch - Fatal编程技术网

Ios UITableViewcontentInset:将表格滚动到顶部时,第一个标题上方的行仍然可见

Ios UITableViewcontentInset:将表格滚动到顶部时,第一个标题上方的行仍然可见,ios,objective-c,uitableview,cocoa-touch,Ios,Objective C,Uitableview,Cocoa Touch,我有一个由1个标题和1行按顺序组成的表: Header Row Header Row 我已经设置了contentInset,以降低表格的起始位置,以显示内容: self.detailTableView.contentInset = UIEdgeInsetsMake(30.0, 0.0, 0.0, 0.0); 但是,当滚动表格时,表格行的内容在第一个标题上方可见。它们不是消失,而是在30像素的上边缘内可见。如何隐藏它们呢?这样滚动就可以正常工作。使用这样的多个部分来实现您想要的内容 - (N

我有一个由1个标题和1行按顺序组成的表:

Header
Row
Header
Row
我已经设置了
contentInset
,以降低表格的起始位置,以显示内容:

self.detailTableView.contentInset = UIEdgeInsetsMake(30.0, 0.0, 0.0, 0.0);

但是,当滚动表格时,表格行的内容在第一个标题上方可见。它们不是消失,而是在30像素的上边缘内可见。如何隐藏它们呢?这样滚动就可以正常工作。

使用这样的多个部分来实现您想要的内容

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 2 ;
 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      if (section==0)
      {
             return [array1 count];
      }
      else{
             return [array2 count];
      }
 }

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
      if(section == 0)
           return @"Section 1";
      else
           return @"Section 2";
 }


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

      static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
      }

 if (indexPath.section==0) {
     ObjectData *theCellData = [array1 objectAtIndex:indexPath.row];
     NSString *cellValue =theCellData.category;
     cell.textLabel.text = cellValue;
 }
 else {
     ObjectData *theCellData = [array2 objectAtIndex:indexPath.row];
     NSString *cellValue =theCellData.category;
     cell.textLabel.text = cellValue;
 }
     return cell;        
 }

我假设您在表视图中有粘性标题

如果要在顶部添加填充,只需设置表格标题视图:

tableView.tableHeaderView = UIView(frame:CGRect(x: 0, y: 0, width: view.frame.width, height: 30))

我不确定我们是否了解对方。我的问题是,我需要在滚动后将表的内容隐藏在第一个标题上方。我不想更改表的结构。如果您使用section,那么它将自动隐藏标题。您可以分享问题的屏幕截图吗?我不清楚