LoginSignup
48
46

More than 5 years have passed since last update.

Storyboardで定義したViewControllerを呼び出す

Posted at

複数の画面からModalで設定画面を呼びたいケースがあったので、
その時の手法をメモ。

  1. Storyboard上で、ViewControllerを定義する
  2. Storyboard上で、ViewControllerのStoryboardIDを定義する
  3. 呼び出したいクラスで下記のコードを実行する
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UINavigationController *nc = [storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];
    [self presentViewController:nc animated:YES completion:nil];

注意

上記のコードのようにUINavigationControllerを呼び出す場合には、
Storyboard上でUINavigationControllerのStoryboardIDを定義する。

ViewControllerのみを呼び出す場合には、
Storyboard上でViewControllerのStoryboardIDを定義する。

48
46
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
48
46