i want to get topMostVC so i did this function:
func topMostViewController() -> UIViewController {
if let presented = self.presentedViewController {
return presented.topMostViewController()
}
if let navigation = self as? UINavigationController {
return navigation.visibleViewController?.topMostViewController() ?? navigation
}
if let tab = self as? UITabBarController {
return tab.selectedViewController?.topMostViewController() ?? tab
}
return self
}
Then called using:
AppDelegate.shared.window?.rootViewController?.topMostViewController()
But i have problem is when UIAlertController is showing in screen, it's return UIAlertController, not my expect viewcontroller
Can anyone tech me how to avoid UIAlertController, thanks
Just add one more condition
if let presented = self.presentedViewController,
!(presented is UIAlertController) { // <== Here or use !presented.isKind(of: UIAlertController.self)
return presented.topMostViewController()
}
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.