LoginSignup
0
0

More than 5 years have passed since last update.

StoryBoardで作成したVIewControllerを参照する

Last updated at Posted at 2016-12-05

StoryBoardで作成したViewControllerをコード上で参照する

ModalでViewControllerを呼び出すときにNavigationbarが挟まっていると少しはまったのでメモ。
大枠はNavigationControllerを呼んで、TopのViewControllerを取得する。

スクリーンショット 2016-12-05 19.19.44.png

まずNavigationControllerの「Identity -> StorybordID」をnavとしておく

コード上で参照

let navView:UINavigationController =
self.storyboard!.instantiateViewController(withIdentifier: "nav") as! UINavigationController

その先のViewControllerを参照するには

let TopView = navView.topViewController as! UIViewController

これでナビゲーションバー付きのViewControlerを扱える

遷移する場合はnavViewを指定。

self.present(navView as UIViewController, animated: true, completion:nil)
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