UITableView分割线距左边有距离的办法
首先在viewDidLoad方法中加上如下代码:
1 if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { 2 3 [self.tableView setSeparatorInset:UIEdgeInsetsZero]; 4 5 } 6 7 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { 8 9 [self.tableView setLayoutMargins:UIEdgeInsetsZero]; 10 11 }
然后在willDisplayCell方法中加入如下代码:
1 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 2 3 { 4 5 if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { 6 7 [cell setSeparatorInset:UIEdgeInsetsZero]; 8 9 } 10 11 if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { 12 13 [cell setLayoutMargins:UIEdgeInsetsZero]; 14 15 } 16 17 }