self.presentingViewController returns UITabBarController not the view controller pushing it with presentModalViewController

前端 未结 2 1074
情深已故
情深已故 2021-02-13 17:08

I have a tab based application. One of the views in it is pushing a modal view controller. If I call self.presentingViewController

2条回答
  •  孤街浪徒
    2021-02-13 17:35

    From Apple's documentation:

    The default implementation of this property walks up the view hierarchy, starting from this view controller. The first view controller it finds that received the presentViewController:animated:completion: method, or that has its definesPresentationContext property set to YES is returned as the value of the property. It keeps walking up the hierarchy until it finds a value to return or it gets to the root view controller.

    So, even though the other view controller pushed it, that view controller's view is covered by the modal view. They walk up the hierarchy until it finds a view controller that doesn't have its view obscured, or has definesPresentationContext set to YES, or until it reaches the root view controller, which in your case was the Tab Bar Controller.

    I would say that the presenting view controller needs to set definesPresentationContext to YES to answer your question on how to return that view controller that presented the modal one.

提交回复
热议问题