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];

}

}

這樣,空白就沒有了
相關文章
相關標籤/搜索