当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。

如何移除这些单元格?


当前回答

如果您不希望在最后一个单元格之后有任何分隔符,那么您需要为页脚设置一个接近零但非零的高度。

在你的UITableViewDelegate中:

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return .leastNormalMagnitude
}

其他回答

试试这个

针对Objective C

- (void)viewDidLoad 
 {
  [super viewDidLoad];
  // This will remove extra separators from tableview
  self.yourTableView.tableFooterView = [UIView new];
}

为迅速

override func viewDidLoad() {
 super.viewDidLoad()
 self.yourTableView.tableFooterView = UIView()
}

只需添加一个视图,以所需的分隔符颜色为背景色,宽度为100%,高度为1px,位置为x0 y-1到你的tableViewCell。确保tableViewCell不剪辑子视图,而应该是tableView。

所以你得到了一个绝对简单的和工作的分离只在现有的单元之间没有任何hack每个代码或IB。

注意:在垂直顶部反弹时,第一个分隔符会出现,但这应该不是问题,因为这是iOS的默认行为。

迅速:

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.tableFooterView = UIView()
    }

在Swift中(我使用4.0),你可以通过创建一个自定义UITableViewCell类来实现这一点,并覆盖setSelected方法。然后分隔符将全部插入到0。(我的主类与表视图有一个清晰的背景)颜色。

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // eliminate extra separators below UITableView
    self.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}

只需添加这个代码(Swift)。

tableView.tableFooterView = UIView()