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?
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.