UITableViewCell左侧会有默认15像素的空白

ios7中,UITableViewCell左侧会有默认15像素的空白。设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。ios

ios8中,setSeparatorInset:UIEdgeInsetsZero 的设置已经不起做用了。代理

下面是解决办法,首先在viewDidLoad方法加入如下代码:io

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])table

{select

     [self.tableView setSeparatorInset:UIEdgeInsetsZero];ios7

}ios8

if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])方法

 {tab

     [self.tableView setLayoutMargins:UIEdgeInsetsZero];view

}

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

       }

}

相关文章
相关标签/搜索