I would like to check whether a certain UIViewController
was modally presented or not. In addition to that I would like to differ if it is modally presented in the TabBar or not. I found the following extension
under this link:
extension UIViewController {
var isModal: Bool {
if let index = navigationController?.viewControllers.index(of: self), index > 0 {
return false
} else if presentingViewController != nil {
return true
} else if navigationController?.presentingViewController?.presentedViewController == navigationController {
return true
} else if tabBarController?.presentingViewController is UITabBarController {
return true
} else {
return false
}
}
}
However, this extension
does not differ between the UIViewController
being presented in the TabBar or out side the tab bar (I get the same result). Removing the last else if
still returns the same Boolean
(both return true
) and so does removing the second last one (both return false
).
I would like to add a "go back" button if it's been presented outside the tabbar.
EDIT:
I have a tabbar under which the user can open his own profile. If that tabbaritem is tapped, the user gets to see his own profile (presented through tabbar). However, he may also get to see his own profile by tapping his own username in another tabbaritem (e.g. in the home feed). In the latter case (since there has been another view controller before his own profile) I want the user to be able to go back to the home feed again (which wouldn't be possible in the former).