Static Cells で定義した TableView から、緑の cell を消す
cell の height を 0 にする
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 4 {
return 0
}
return super.tableView(tableView, heightForRowAt: indexPath)
}
height を 0 にしただけなので、Storyboard 上には緑の cell は残り続ける。気持ち悪い…。
cell のロードをスキップする
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return super.tableView(tableView, numberOfRowsInSection: section) - 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row > 3 {
return super.tableView(tableView, cellForRowAt: IndexPath(row: indexPath.row + 1, section: 0))
}
return super.tableView(tableView, cellForRowAt: indexPath)
}
前述の方法よりコード量は多くなるが、無駄な cell をロードするコストが減る。