LoginSignup
35
33

More than 5 years have passed since last update.

逆引きUIStoryboard

Posted at

任意のstoryboardを取得する

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];

storyboardから任意のビューコントローラを取得する

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];

// initial view controllerを取得する
UIViewController *vc = [storyboard instantiateInitialViewController];

// Storyboard IDから取得する
MBLoginViewController *loginVc = [storyboard instantiateViewControllerWithIdentifier:@"loginViewController"];

Storyboard IDって何?

Storyboard内でViewControllerに定義したIDです。

kobito.1400224181.136167.png

Initial View Controllerって何?

Storyboard内で最初に表示されるViewControllerです。

kobito.1400224050.404908.png

プログラムからsegueを実行する

Storyboard Segueはこんなかんじ。

// ViewControllerからStoryboard Segueを指定してsegueを実行する
[self performSegueWithIdentifier:@"show_login" sender:self];

kobito.1400224512.201717.png

Segueの実行に割り込みをかける

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"show_login"]) {
        // destinationViewController:から遷移先のビューコントローラを取得する
        MBLoginViewController *loginViewController = [segue destinationViewController];
        loginViewController.delegate = self;
    }
}
35
33
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
35
33