ios8 UITableView设置 setSeparatorInset:UIEdgeInsetsZero不起做用的解决办法

 本文转载至 http://blog.csdn.net/yesjava/article/details/41039961
在ios7中,UITableViewCell左侧会有默认15像素的空白。这时候,设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。

可是在ios8中,设置setSeparatorInset:UIEdgeInsetsZero 已经不起做用了。下面是解决办法java

首先在viewDidLoad方法加入如下代码:ios

 

 if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {spa

[self.tableView setSeparatorInset:UIEdgeInsetsZero];.net

}代理

if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {blog

[self.tableView setLayoutMargins:UIEdgeInsetsZero];it

}io

而后在UITableView的代理方法中加入如下代码

 

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPathtable

{class

if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

[cell setSeparatorInset:UIEdgeInsetsZero];

}

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

[cell setLayoutMargins:UIEdgeInsetsZero];

}

}

这样,空白就没有了