Get top most UIViewController

后端 未结 24 2275
别那么骄傲
别那么骄傲 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条回答
  •  我在风中等你
    2020-11-22 15:43

    To find the visible viewController in Swift 3

    if let viewControllers = window?.rootViewController?.childViewControllers {
    
         let prefs = UserDefaults.standard
    
         if viewControllers[viewControllers.count - 1] is ABCController{
            print("[ABCController] is visible")
    
         }
    }
    

    This code find the last added or the last active controller visible.

    This I have used in AppDelegate to find active view Controller

提交回复
热议问题