3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

instantiateViewControllerWithIdentifierを使ってVCを生成する

Posted at

ストーリーボードにあるViewControllerを自前で生成する方法を書きます。

1.is initial View Controllerのチェックを外してあること(超重要)
2.Storyboard IDを設定してあること
3.コードを書いて呼び出すこと。

以上。

尚、Webには、1.をするのを忘れている記事が多いので、注意しませう。

コードはだいたい以下を参照するとルートに。あと遷移は適当にどうぞ。

ObjC.m
	//自前で生成する
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //application launch後の、カスタマイズコードを記述する。
    self.window.backgroundColor = [UIColor whiteColor];
    //表示ON
    [self.window makeKeyAndVisible];
    //ストーリーボードSubのIDがViewControllerのビューコントローラを生成
    UIViewController *rootVC = [[UIStoryboard storyboardWithName:@"Sub" bundle:nil]instantiateViewControllerWithIdentifier:@"ViewController"];
    //windowのルートビューコントローラに設定
    self.window.rootViewController = rootVC;
    //windowにsubビューを追加する
    [self.window addSubview:[rootVC view]];
    
3
5
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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?