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

来源:互联网 发布:2002世界杯黑哨知乎 编辑:程序博客网 时间:2024/05/22 12:14

ios7中,UITableViewCell左侧会有默认15像素的空白。这时候,设置setSeparatorInset:UIEdgeInsetsZero能将空白去掉。

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

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


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

[self.tableView setSeparatorInset:UIEdgeInsetsZero];

}

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

[self.tableView setLayoutMargins:UIEdgeInsetsZero];

}

然后在UITableView的代理方法中加入以下代码


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

{

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

[cell setSeparatorInset:UIEdgeInsetsZero];

}

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

[cell setLayoutMargins:UIEdgeInsetsZero];

}

}

这样,空白就没有了

0 0
原创粉丝点击