【问题标题】:UITableView top and button separator inset not workingUITableView 顶部和按钮分隔符插入不起作用
【发布时间】:2014-01-18 03:18:46
【问题描述】:

我正在尝试在我的表格视图中设置插图,以便每个单元格不会相互粘连。

为此,我在tableView:willDisplayCell:forRowAtIndexPath 中添加了以下方法:

if([tableView respondsToSelector:@selector(setSeparatorInset:)]){
    [tableView setSeparatorInset:UIEdgeInsetsMake(10, 15, 10, 15)];
}

我基本上想要一个 10pt 空间在单元格的顶部和底部,在下一个单元格之前。此代码部分有效,因为左右两侧都有可见的 15pt 插图。但是,顶部和底部仍然相连。

谢谢!

~地毯嘶嘶声

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    忽略顶部和底部值UITableViewCell Class Reference (separatorInset)

    [...]仅考虑左右插入值;顶部和底部插入值被忽略。[...]

    我建议通过增加单元格的高度来设置间距,并在顶部和底部边缘放置适当的填充内容。

    【讨论】:

      【解决方案2】:

      您必须为此使用透明单元格。 以一小部分代码为例。

      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
      {
          return yourCount*2;
      }
      
      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          static NSString *CellIdentifier = @"elementCell";
          static NSString *TransparentCellIdentifier = @"transparentCell";
      
          NSString *neededIdentifier;
      
          if(indexPath.row % 2 != 0)
              neededIdentifier = TransparentCellIdentifier;
          else
              neededIdentifier = CellIdentifier;
      
          UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:neededIdentifier];
          if(cell == nil) {
              cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:neededIdentifier];
          }
          if([neededIdentifier isEqualToString:TransparentCellIdentifier]) {
              [cell setBackgroundColor:[UIColor clearColor]];
              cell.userInteractionEnabled = NO;
          }
          else {
              [cell setBackgroundColor:[UIColor redColor]];
              cell.userInteractionEnabled = YES;
          }
          return cell;
      }
      
      -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
          if(indexPath.row % 2 == 0)
              return 70.0f;
          else
              return 10.0f;
      }
      

      是的,这有点奇怪,但它确实有效。

      【讨论】:

        猜你喜欢
        • 2014-11-04
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        • 2016-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多