ios7中,UITableViewCell左侧会有默认15像素的空白。设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。
ios8中,setSeparatorInset:UIEdgeInsetsZero 的设置已经不起作用了。
下面是解决办法,首先在viewDidLoad方法加入以下代码:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在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];
}
}
转自:http://blog.csdn.net/mrliuzhe/article/details/41997411
那么,当tableView是IB生成的怎么办呢?以上方法在本人的项目中就不起作用了。
那么,解决方案就是:
1.在IB中设置Separator为None;
2.在cell的xib中放一条细长的View,颜色就随便选了。