Storyboard/xib から生成した ViewController を NavigationController 下にホストする
Storyboard/xib から NavigationController にホストされた ViewController を作りたい場合、Storyboard 上で先に NavigationController をホストする方法もありますが、この場合、自分で作った ViewController に変数を渡したい時が面倒です。
・Storyboard 上で NavigationController にホストされた ViewController の例
そこで、Storyboard 上には Navigation Controller を生成せず、コードで NavigationController を追加します。
let vc = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("storyboardId") as! UIViewController
vc.some_variable = xxx // ここで変数を渡す
let navigationVC = UINavigationController(rootViewController: newsVC) // navigation controller にホストさせる
これで NavigationController にホストされた ViewController に変数を渡しやすくなりました。
おまけ - 生成した ViewController を Tab の一部にする
この生成した NavigationController を Tab の一部にしたい場合、 tabBarItem を設定してあげると Tab 中にアイコン・名称が表示されるようになります。
vc.tabBarItem = UITabBarItem(title: "ニュース", image: UIImage(named: "News"), tag: 0)
このように表示されるようになります。
Author And Source
この問題について(Storyboard/xib から生成した ViewController を NavigationController 下にホストする), 我々は、より多くの情報をここで見つけました https://qiita.com/takecian/items/f3824995947189ff7332著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .