解決UITableView分割線(xiàn)距左邊有距離的辦法炕柔,有需要的朋友可以參考下酌泰。
我們?cè)谑褂胻ableview時(shí)會(huì)發(fā)現(xiàn)分割線(xiàn)的左邊會(huì)短一些,通池袄郏可以使用setSeparatorInset:UIEdgeInsetsZero 來(lái)解決陵刹。但是升級(jí)到XCode6之后,在iOS8里發(fā)現(xiàn)沒(méi)有效果欢嘿。下面給出解決辦法:
首先在viewDidLoad方法中加上如下代碼:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在willDisplayCell方法中加入如下代碼:
- (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];
}
}
這樣就可以正常顯示了衰琐。