自定义UITableView分隔符插件无法在带有故事板的iOS 8上运行.

我的应用程序的所有tableViews都不遵守storyBoard上的属性SeparatorInset- Custom – left = 0.它在iOS 7上运行良好,但现在不再适用了.

当我实现以下两种方法时:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // iOS 7 
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    // iOS 8 
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)viewDidLayoutSubviews
{
    // iOS 7 
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    // iOS 8 
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

它工作正常,我只是不明白为什么我不能在故事板上设置这个更简单.

有什么想法吗?

解决方法

此代码可能对您有所帮助.
包括layoutMargins和separatorInset,以支持iOS版本7,8
对于iOS8:

首先配置表视图,如下所示:

if ([self.tableView respondsToSelector:@selector(layoutMargins)]) {
    self.tableView.layoutMargins = UIEdgeInsetsZero;
}

然后在您的cellForRowAtIndexPath:方法中,按如下方式配置单元格:

if ([cell respondsToSelector:@selector(layoutMargins)]) {
    cell.layoutMargins = UIEdgeInsetsZero;
}

对于版本检查,您可以使用以下内容:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
  if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
    cell.layoutMargins = UIEdgeInsetsZero;
  }
#endif

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...