Reputation: 931
In another file I'm creating an instance of my view controller from another storyboard and presenting it like so:
let viewController:UIViewController = UIStoryboard(name: "UserProfile", bundle: nil).instantiateViewControllerWithIdentifier("profileID") as! ProfileViewController
self.presentViewController(viewController, animated: true, completion: nil)
In my storyboard I have the correct storyboard ID and embedded my view controller in a UINavigationController. I also set the initial view controller to the UINavigationController.
Why isn't it showing up?
Upvotes: 2
Views: 4333
Reputation: 4765
For the ones who still use Objective-C:
UIStoryboard *sb = [UIStoryboard storyboardWithName: @"Storyboard" bundle: [NSBundle mainBundle]];
ViewController *vc = [sb instantiateInitialViewController];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController: vc];
[self presentViewController:nc animated:YES completion:nil];
Don't forget to thick the button:
Upvotes: 0
Reputation: 2306
Ok, so you're presenting the view controller (Please note, it's not navigation controller).
What you can do:
Push the view controller
let viewController:UIViewController = UIStoryboard(name: "UserProfile", bundle: nil).instantiateViewControllerWithIdentifier("profileID") as! ProfileViewController
[self.navigationController pushViewController:viewController animated:YES];
Present the navigation controller
let viewController:UIViewController = UIStoryboard(name: "UserProfile", bundle: nil).instantiateViewControllerWithIdentifier("profileID") as! ProfileViewController
let navigationController = UINavigationController(rootViewController: viewController)
self.presentViewController(viewController, animated: true, completion: nil)
Upvotes: 2
Reputation: 306
create object of view controller then add navigation controller to it, and then present it :
let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("MyViewController") as! ViewController
let navController = UINavigationController(rootViewController: VC1) // Creating a navigation controller with VC1 at the root of the navigation stack.
self.presentViewController(navController, animated:true, completion: nil)
Upvotes: 8