开发者

Is there a way to know if a UIViewController has been presented and dismissed modally ?

开发者 https://www.devze.com 2023-04-03 04:08 出处:网络
Is there a way to know if a UIViewController 开发者_运维百科has been presented and dismissed modally ?

Is there a way to know if a UIViewController 开发者_运维百科has been presented and dismissed modally ?

Something like:

  • hasBeenPresentedModally
  • hasBeenDismissedModally

thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消