LoginSignup
0
0

More than 1 year has passed since last update.

特定のセルだけ表示する方法

Last updated at Posted at 2021-09-27

結論から言うと、高さを限りなく0にすることで実装が可能です。
そしてソースコードはこちら。
 

func tableView(_ newsTable: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if ここに条件 {
        // 表示したい条件の場合
        return 25
    } else {
        // 消したい条件の場合
        return 0.1
    }
    return 0.1
}

 
該当のコードを加える前
スクリーンショット 2021-09-28 0.37.29.png
 
該当のコードを加えた後
スクリーンショット 2021-09-28 0.37.56.png

必要のないセルは非表示にすればいいんじゃないかと思い、cell.isHidden = trueで消そうとしたんですが、セルの中の文字が消えるだけでセル自体が消えなかったので、こちらの方法を取りました。

特定のセルだけ表示する方法が知りたい方は参考にしていただけたら幸いです。

0
0
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
0
0