Lion789
Lion789

Reputation: 4482

Storyboard View Controller not instantiated?

I am trying to instantiate a new view controller in my storyboard with this code but it does nothing and stays on the old storyboard.

Here is the code:

(void)menuSelect:(id)sender {
UIButton *button = (UIButton*) sender;
switch (button.tag) {
    case 0: {
        HomeViewController *hc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Home"];
        [self presentViewController:hc animated:YES completion:nil];

        break;
    }

The storyboard file name is Main.Storyboard and the id for the viewController is Profile.

Here is the image of what the storyboard looks like:

enter image description here

Upvotes: 1

Views: 339

Answers (2)

E-Riddie
E-Riddie

Reputation: 14780

Issue

You are passing "home" as an indentifier of HomeViewController, while it is "profile". So what you are telling to program is: Get the storyboard with the name "main", instantiate the HomeViewController with identifier "home".

Solution

Change the code to:

HomeViewController *hc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Profile"];
[self presentViewController:hc animated:YES completion:nil];

Upvotes: 5

Daniel
Daniel

Reputation: 9040

Instantiating the storyboard does not cause any View Controller to be displayed. You have to call presentViewController from another view controller.

Upvotes: 1

Related Questions