如何删除第一个单元格顶部的分隔符和最后一个单元格底部

我需要删除特定部分的第一个单元格的顶部边框forms和特定部分的最后一个单元格的底部边框forms。

我GOOGLE了解决scheme完整隐藏分隔符tableView,但我想避免它。

另外我发现解决scheme时,当细胞将显示玩分离器插入事件。 它适用于两个单元格之间的中间分隔符,但不适用于页眉/页脚和单元格之间的分隔符。

另外,我试图看到标题中的子层,但由于这个视图是由我自己创build的,我没有find分隔视图。

可能是我应该在头里面的层工作? 请给我一个线索。

在你的ViewDiDLoad

  - (void)viewDidLoad { [super viewDidLoad]; yourTableview.tableFooterView=[[UITableView alloc]initWithFrame:CGRectZero]; } - (UIEdgeInsets)layoutMargins { return UIEdgeInsetsZero; } -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { [tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) { [tableView setLayoutMargins:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } if ( indexPath.row == tableData.count-2 ) { cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, CGRectGetWidth(tableView.bounds)); } else { // do nothing } } 

最终的输出是

在这里输入图像说明

下面的代码可以帮助我从UITableView的最后一行删除分隔符。

Swift 3.0

 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { if indexPath.row == tableView.numberOfRows(inSection: indexPath.section) { cell.separatorInset.right = cell.bounds.size.width } } 
 - (void)layoutSubviews { [super layoutSubviews]; for (UIView *subview in self.contentView.superview.subviews) { if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"] && subview.frame.origin.x == 0 ) { subview.hidden = YES; }else { subview.hidden = NO; } } } 

对我来说,事实certificate,所有这种视图黑客方式比创build自己的UITableViewCell子类更复杂,你将一个1p高UIView作为你自己的分隔符,并将其隐藏在cellForRowAtIndexPath中:基于事实,如果indexPath是该部分中的最后一行。

一旦你了解如何创build自定义的UITableViewCells,这实际上是一件非常容易的工作。 它也比黑客苹果devise更安全,更有前途。 它们为您提供适合整个系统风格的分隔符。 不是他们所做的一切都是为了定制到最大。

在分隔符的情况下,我认为这只是最好的或者与他们的风格生活,或者只是想出了自己的分隔视图的实现。