Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top most view controller ? #129

Open
subhash08 opened this issue Oct 13, 2018 · 0 comments
Open

Top most view controller ? #129

subhash08 opened this issue Oct 13, 2018 · 0 comments

Comments

@subhash08
Copy link

subhash08 commented Oct 13, 2018

I'm using your DrawerController , thank you for awesome library.
My issue:

I'm using KYDrawerController with UITabbarController, I need to get Top Most controller of the application which is showing now but I'm not able to get correct one.

here is the code I'm using.

extension UIViewController {
    func topMostViewController() -> UIViewController {
        if let navigation = self.presentedViewController as? UINavigationController {
            if let visibleController = navigation.visibleViewController {
                return visibleController.topMostViewController()
            }
        }
        if let tab = self.presentedViewController as? UITabBarController {
            if let selectedTab = tab.selectedViewController {
                return selectedTab.topMostViewController()
            }
            return tab.topMostViewController()
        }
        if self.presentedViewController == nil {
            return self
        }
        
        return self.presentedViewController!.topMostViewController()
    }
}

extension UIApplication {
    func topMostViewController() -> UIViewController? {
        return self.keyWindow?.rootViewController?.topMostViewController()
    }
}

Please correct me if I'm using wrong approch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant