LoginSignup
2
1

More than 5 years have passed since last update.

UIViewControllerでUITableViewのStatic Cellsを使う

Last updated at Posted at 2018-10-09

はじめに

iOSアプリを作りながら勉強している大学生です。
自分が躓き、自分なりに解決策を見つけられたので書き起こしました。
素人なので、わかりにくい場合はご容赦ください🙏

Static Cellsとは

Static Cellsとは、セルを静的に扱うUITableViewのコンテントモードのことです。
IMG_3859.PNG
よくみるのは、設定画面のUITableViewではないでしょうか。

Static cellsはUIViewControllerでは使えない

UITableViewControllerを親要素としないとエラーを吐いてしまう。
スクリーンショット 2018-10-09 9.53.00.png

Container Viewを使って解決

TableViewだとレイアウトの幅があまりない… でも、Static cellsはUIViewControllerでは使えない…
そんなときは、Container Viewを使ってUIViewControllerを配下に持たせればうまくいきます。
イメージはこんな感じです〜↓↓↓
(Container ViewとUITableViewControllerは「Embed」で結びます。)
スクリーンショット 2018-10-09 10.04.52.png
UIViewControllerの上にContainer Viewを置き、Container Viewの中にUITableViewControllerを入れてやるって感じです。

他のViewと組み合わせる

Segment Buttonと組み合わせて、画面を作ってみました。
iOS の画像.png
iOS の画像 (1).png

Static Cellsを使うとiOSっぽい(?)デザインで簡単に画面が作れるような気がしました。
TableViewすごく便利!

参考サイト

2
1
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
2
1