IOS8 设置TableView Separatorinset 分割线从边框顶端开始

  这个问题出现了很多次,每次都是度娘,command +c,command + v,写完后就忘记了,今天特此记录下:

 

  在ios8上 [TableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];不起作用。

  可以在tableview创建都地方添加如下代码:  

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {  
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];  
    }  
      
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {  
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];  
    }  

 

  然后在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];  
    }  
}  

 

posted on 2015-08-14 14:20  karen我心永恒  阅读(204)  评论(0编辑  收藏  举报

导航