aur0n
aur0n

Reputation: 473

Load View Controller via code

I've got my storyboard with several ViewControllers, connected each other via buttons.

Now I need that if a particular condition is true, to load another UIViewController. I managed to do it creating a new subclass, but I would like to avoid it. I just want

if(condition == true){
  // load viewcontroller located in the storyboard, not connected with anything else
}

Any help?

Upvotes: 2

Views: 2525

Answers (1)

ksh
ksh

Reputation: 1904

Ok, I'll elaborate: Use should use - (id)instantiateViewControllerWithIdentifier:(NSString *)identifier method of UIStoryBoard class, but make sure to fill in identifier field of your controller in IB.

UIStoryboard *storybrd = [UIStoryboard storyboardWithName:@"YourStoryBrdName" bundle:nil];
UIViewController *mycontroller =[storybrd instantiateViewControllerWithIdentifier:@"myIdent"];

Now you should have your controller and present it as you like.

Upvotes: 5

Related Questions