LoginSignup
7
6

More than 1 year has passed since last update.

途中のViewからUINavigationControllerを使う

Last updated at Posted at 2015-10-06

Problem

アプリ全体をナビゲーションコントローラーで管理したくはないが、一部でナビゲーションコントローラを使いたい。

Solution

StoryboardにUINavigationControllerを追加する

  • StoryboardにUIViewControllerをドラッグする
  • UIViewControllerが選択された状態で、Editor > Embed in > NavigationController

nav1.png

  • NavigationControllerにStoryboard IDをつける。ここではNavigationVCにした。

nav2.png

NavigationControllerに遷移するためのコードを書く

class MainViewController: UIViewController {

  func presentNavigationViewController() {
    let navigationVC = self.storyboard?.instantiateViewControllerWithIdentifier("NavigationVC")   as! UINavigationController
    presentViewController(navigationVC, animated: false, completion: nil)
  }
}
7
6
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
7
6