Reputation: 4482
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:
Upvotes: 1
Views: 339
Reputation: 14780
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".
Change the code to:
HomeViewController *hc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Profile"];
[self presentViewController:hc animated:YES completion:nil];
Upvotes: 5
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