iOS8下设置table的分割线,左侧总是有间距

原因:

 ios7的时候在storyboard 设置 TableView的separator intend = 0 可以让tableview的分割条顶到头。

但是,升级了iOS8时,发现不起作用了。iOS8 在cell和tableview中都引入了layoutMargins属性,而且这个属性在iOS 7中并没有,所以你需要区别对待这两个版本。

解决办法如下:

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

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
 
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
 
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章