Skip to content

Commit

Permalink
Merge pull request #6 from devxoul/topmostviewcontroller
Browse files Browse the repository at this point in the history
Improve topMostViewController()
  • Loading branch information
devxoul committed Mar 2, 2016
2 parents dc40c1c + f8e0b86 commit 6b56711
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/UIViewController+TopMostViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension UIViewController {

/// Returns the current application's top most view controller.
class func topMostViewController() -> UIViewController? {
let rootViewController = UIApplication.sharedApplication().keyWindow?.rootViewController
let rootViewController = UIApplication.sharedApplication().windows.first?.rootViewController
return self.topMostViewControllerOfViewController(rootViewController)
}

Expand All @@ -49,6 +49,13 @@ extension UIViewController {
return self.topMostViewControllerOfViewController(presentedViewController)
}

// child view controller
for subview in viewController?.view?.subviews ?? [] {
if let childViewController = subview.nextResponder() as? UIViewController {
return self.topMostViewControllerOfViewController(childViewController)
}
}

return viewController
}

Expand Down

0 comments on commit 6b56711

Please sign in to comment.