Is it possible to determine whether ViewController is presented as Modal?

后端 未结 14 2121
一生所求
一生所求 2020-12-04 07:13

Is it possible to check inside ViewController class that it is presented as modal view controller?

14条回答
  •  一整个雨季
    2020-12-04 08:01

    In iOS5+, As you can see in UIViewController Class Reference, you can get it from property "presentingViewController".

    presentingViewController The view controller that presented this view controller. (read-only)

    @property(nonatomic, readonly) UIViewController *presentingViewController
    Discussion

    If the view controller that received this message is presented by another view controller, this property holds the view controller that is presenting it. If the view controller is not presented, but one of its ancestors is being presented, this property holds the view controller presenting the nearest ancestor. If neither the view controller nor any of its ancestors are being presented, this property holds nil.

    Availability
    Available in iOS 5.0 and later.
    Declared In
    UIViewController.h

提交回复
热议问题