Is there a way to know if a UIViewController has been presented and dismissed modally ?
Something like:
thanks
Try to use modal. If you use push, you should dismiss it with the pop method of the navigation controller.
When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.
First UIViewController is alloc'ed by some other object, then init is immediately called (or some other init method, like initWithStyle). Only once the object is initialized would I expect it to call its own loadView function, after which the view, once loaded, calls the viewDidLoad delegate method.
The LifecycleThe view controller lifecycle can be divided into two big phases: the view loading and the view lifecycle. The view controller creates its view the first time the view is accessed, loading it with all the data it requires. This process is the view loading.
There's nothing built in, but a view controller could, upon receiving viewDidAppear
and/or viewWillDisappear
check whether it has a parentViewController
, since per Apple's documentation (emphasis added):
Parent view controllers are relevant in navigation, tab bar, and modal view controller hierarchies. In each of these hierarchies, the parent is the object responsible for displaying the current view controller. If you are using a view controller as a standalone object—that is, not as part of a view controller hierarchy—the value in this property is nil.
If it has then it can set suitable flags for future reference.
Note that being presented modally is different from being truly modal. For example, on an iPad you might put one controller inside a UIPopoverController
, so that controller isn't presented modally, but then it might modally present another controller on top of itself. So the second controller is presented modally but isn't itself a modal dialogue because — if the program is otherwise set up suitably — the user can just ignore the popover entirely.
Check if your UIViewController's parentViewController
property is nil
or not.
If the property is nil
then it's dismissed otherwise it's presented.
NOTE: UITableViewController's childViewController's parentViewController
property would also be not nil
, you should also make sure the parentViewController is not UITableViewController.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With