我的应用程序的所有 tableViews
都不符合 property
SeparatorInset
- Custom
- left = 0
在 storyBoard
上。在 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];
}
}
它工作正常,我只是不明白为什么我不能在简单得多的 storyboard
上继续设置它。
有什么想法吗?
最佳答案
此代码可能对您有所帮助。 包括 layoutMargins 和 separatorInset,以支持 iOS 7,8 版本 对于 iOS8:
首先按如下方式配置您的 TableView :
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 - 自定义 UITableView 分隔符插图不适用于 iOS 8 的 Storyboard。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25975043/