Reputation: 11
I'm trying to load a particular scene from storyboard dynamically using it's story board id. It is more like loading a separate nib file through storyboard. I have a scene with a storyboard id "storyid". Then I'm trying to load it but unable get that scene on my screen when it is loaded. I get no errors in the code.
- (IBAction)btnLoadSceneClicked:(id)sender
{
NSLog(@"btnLoadSceneClicked");
[self.storyboard instantiateViewControllerWithIdentifier:@"storyid"];
}
Upvotes: 0
Views: 1138
Reputation: 4091
- (IBAction)btnLoadSceneClicked:(id)sender
{
NSLog(@"btnLoadSceneClicked");
YourViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardID"];
[viewController.view setFrame:CGRectMake(160, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:viewController.view];
[UIView animateWithDuration:0.50f animations:^{
[viewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
} completion:^(BOOL finished) {
}];
}
Upvotes: 0
Reputation: 3718
YourViewControllerClass * viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"storyid"];
[self presentViewController: animated:YES completion:^{ /* what happens when the viewController is presented */}]
You could also push the viewController if you are embedded in a navigation controller.
[self.navigationController pushViewController:viewController animated:YES];
Upvotes: 2