iOS開發中關于沒有數據時不顯示tableView的分割線
//可以直接添加如下代碼即可
self.tableView.tableFooterView = [[UIView alloc]init];
我們在使用tableview時會發現分割線的左邊會短一些,通??梢允褂胹etSeparatorInset:UIEdgeInsetsZero 來解決。但是升級到XCode6之后,在iOS8里發現沒有效果。下面給出解決辦法:
首先在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];
}
}
這樣就可以正常顯示了。
設置分割線的顏色
self.tableView.separatorColor = [UIColor redColor];