Get top most UIViewController

后端 未结 24 2147
别那么骄傲
别那么骄傲 2020-11-22 14:47

I can\'t seem to get the top most UIViewController without access to a UINavigationController. Here is what I have so far:

UIApplic         


        
24条回答
  •  萌比男神i
    2020-11-22 15:33

    Where did you put the code in?

    I try your code in my demo, I found out, if you put the code in

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    

    will fail, because key window have been setting yet.

    But I put your code in some view controller's

    override func viewDidLoad() {
    

    It just works.

提交回复
热议问题