我的应用程序的所有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:
包括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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。