LoginSignup
1
3

More than 5 years have passed since last update.

特定の Static Cell を消す

Posted at

Static Cells で定義した TableView から、緑の cell を消す

1518172925454.JPEG

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 は残り続ける。気持ち悪い…。

スクリーンショット 2018-02-09 13.26.25.png

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 をロードするコストが減る。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3