I have added a NavigationController in the StoryBoard and made it the initial viewController. How do I get access to the NavigationController in the appDelegate. Ctrl-drag from navigationController to AppDelegate does not create an outlet.
Swift: How do I get access to the navigationController in AppDelegate
Asked Answered
In didFinishLaunchingWithOptions
:
let navigationController = application.windows[0].rootViewController as! UINavigationController
Getting this SIGBART error : Could not cast value of type 'SwiftControlsTest.ViewController' (0x1006303f0) to 'UINavigationController' (0x101ecb670). –
Tannatannage
That's because you don't have a navigation controller set as the root view controller of your application. Your root view controller is a
SwiftControlsTest.ViewController
–
Joellejoellen windows
is deprecated as of iOS 15. Also, you'll get an error if you try to do self.window?.rootViewController
in AppDelegate
; you can, however, do this in SceneDelegate
. –
Unadvised In custom functions use like this:
let navigationController = self.window?.rootViewController as! UINavigationController
© 2022 - 2024 — McMap. All rights reserved.
self.window.rootViewController
– Recruitment