UITableView部分中的iOS7最后一个单元强制使用全宽分隔符

下面的UITableView具有自定义的UITableViewCells ,我可以使用自定义的UITableViewCell中的这一行来调整分隔符:

 self.separatorInset = UIEdgeInsetsMake(0, kDefaultSeparatorLeftInset, 0, 0); 

然而,该部分底部的单元格有一个默认分隔符,它覆盖了我设置的自定义UIEdgeInsets

我想所有的分隔符是相同的宽度,有没有办法做到这一点,而不需要手动重绘分隔符?

UITableView与iOS7中的大节分隔符

经过一番实验,我发现唯一真正的解决scheme是将UITableViewStyle设置为UITableViewStyle ,并使用以下命令设置空页脚:

 -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [[UIView alloc] initWithFrame:CGRectZero]; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01f; } 

这对于某些人来说不是一个令人满意的解决scheme,因为UITableViewStylePlain不提供UITableViewStylePlain所有function,但它给了我没有全宽分隔符的部分。

在这里输入图像说明

经过一些实验,我find了解决办法! tableFooterView可以像这样覆盖分隔符:

 UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)]; UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(0, -1, 320, 2)]; v2.backgroundColor = [UIColor whiteColor]; v.backgroundColor = [UIColor whiteColor]; [v addSubview:v2]; self.tableView.tableFooterView = v; 

在tableView本身上使用separatorInset属性,而不是在单个单元格上。 tableView的separatorInset设置默认插入,这可以被单元格覆盖,以及底部的“额外”单元格的插入。

给桌子一个空的页脚:

 self.tableFooterView = [[UIView alloc] init]