You should make the navigation controller the rootViewController
of your main UIWindow
.
If you create your interface entirely programmatically, it is common in you app delegate application:didFinishLaunchingWithOptions:
to create both the main UIWindow
and the main navigation controller, then assign the latter to the former's rootViewController
property.
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var navigationController: UINavigationController?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.navigationController = UINavigationController()
var viewController: UIViewController = UIViewController()
self.navigationController.pushViewController(viewController, animated: false)
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window.rootViewController = self.navigationController
...more initialisation...
self.window.makeKeyAndVisible()
return true
}
}
EDIT:
Answering your question in the comment:
so is it the same when I create navigation controller from editor -> embedded in navigation controller? I mean like, if I do from editor-> embedded in navigation controller, will it produce the same result as I do programatically?
it depends on how you look at it. from a user viewpoint, I would say, yes. from a programmer's viewpoint, I would say not, because the storyboard will generate a bunch of other objects (related to the scenes, segues, etc.)
In other words, if you are only concerned with creating a navigation view controller and attaching to your window, the storyboard will do that just like I outlined it above (plus the bunch of things that I mentioned before and that do not change the end result of "attaching", just the way of doing it).
If you mean you want to recreate the very same settings as those created in the storyboard, I don't think you can create a new storyboard scene programmatically, because Apple does not make public all the relevant classes.