Reputation: 2029
I need to display from AppDelegate a table view embed to an UINavigationController.
Normally I use
let viewController: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("prova") as ViewController
window?.rootViewController?.presentViewController(viewController, animated: false, completion: nil)
but it doesn't work with embed controller, how need to be adapted this code?
Upvotes: 2
Views: 3211
Reputation: 578
You need to instantiate the UINavigationController
with its identifier from your storyboard. The navigation controller should be connected to its rootViewController in the storyboard and will automatically show it.
let navController: UINavigationController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("provaNavController") as UINavigationController
window?.rootViewController?.presentViewController(navController, animated: false, completion: nil)
Since you are not setting an initial view controller in the storyboard, use this code:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let navController: UINavigationController = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("provaNavController") as UINavigationController
window?.rootViewController = navController
window?.makeKeyAndVisible()
You also need to clear out Main.storyboard from the general project settings:
Upvotes: 4