mzgkworks

iOSを中心にプログラミング関係について書く

【Swift】ContainerViewにEmbedされているViewControllerを変更する

ContainerViewを使用すると、標準でViewControllerがついてくる。
これをTableViewControllerに変える方法。

環境

背景

例えばスライドメニューとかをContainer Viewを使って実装する場合。
ViewControllerよりもTableViewControllerのStatic Cellsを使って簡単にメニューを作りたい。
ちなみにStatic CellsはTableViewControllerでしか使えない。

方法

  1. まずはContainer Viewを追加する(View ControllerがEmbedされる)
  2. EmbedされているView Controllerを削除する
  3. オブジェクトライブラリからTable View ControllerをStoryBoardにドラッグ&ドロップして追加する
  4. ContainerViewからCtrlを押しながらTableViewControllerに接続する
  5. ポップアップが表示されたら「Embed」を選択する

以上