Problem dismissing multiple modal view controllers

后端 未结 9 1645
暗喜
暗喜 2020-12-09 10:43

I am having trouble getting my modal view controllers to display properly. I have a parent view controller that is the delegate for modal view A. In modal v

9条回答
  •  悲&欢浪女
    2020-12-09 11:27

    A modal view controller must have a parent view controller in order to display. If you dismiss the parent view controller ("modal view A", in your case), behavior will be unpredictable.

    If you're certain that nested modal view controllers are what you really want, you'll need to dismiss them in reverse order; wait until you're done with "B", then dismiss "B", then dismiss "A".

    If you don't need the modal presentation style, you would be better off using a UINavigationController to maintain your stack of view controllers.

    Update: here is how I would rearrange your order of events. Presented as code for clarity.

    1. [parentView presentViewController:modalViewControllerA animated:YES]
    2. [modalViewControllerA presentViewController:modalViewControllerB animated:YES]
    3. [modalViewControllerA dismissModalViewControllerAnimated:YES]
    4. [parentView dismissModalViewControllerAnimated:YES]

提交回复
热议问题