我应该在呈现模式的UIViewController或UIViewController上调用dismissViewController吗?

编程入门 行业动态 更新时间:2024-10-27 00:31:26
本文介绍了我应该在呈现模式的UIViewController或UIViewController上调用dismissViewController吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这两种情况下似乎都可以工作,但是为什么以及如何进行,哪一种是最好的方法?

It seems to work in either case, but why and how, and which is the best way?

推荐答案

为什么和如何

比方说,视图控制器A提出了B,而B又提出了C.

Why and How

Let's say, view controller A has presented B, and B has presented C in turn.

当您调用dismissViewControllerAnimated:completion:时,iOS会检查您正在调用它的视图控制器的presentedViewController属性中是否有子代.如果是这样,则解雇该控制器.

When you call dismissViewControllerAnimated:completion:, iOS checks to see if the view controller you're calling it on has a child in its presentedViewController property. If it does, then it dismisses that controller.

因此,如果在我们的示例中在B上调用它,则它会解散C,但是如果在A上调用它,它会解散B(它带走C).

So if I call it on B in our example, it dismisses C, but if I call it on A, it dismisses B (which takes away C with it).

如果我在C上调用它,则它没有子代.因此,iOS会检查presentingViewController属性.如果已设置,它将要求 it 关闭其控制器.因此,如果我在C上调用它,iOS会将请求发送回B,B将驳回C.

If I call it on C, then it has no child. So then iOS checks the presentingViewController property. If that is set, it asks it to dismiss its controller. So if I call it on C, iOS sends the request back to B, which dismisses C.

因此,在B或C上调用该方法将摆脱C,而在A上调用该方法将摆脱B和C.

So calling the method on either B or C will get rid of C, while calling it on A gets rid of B and C.

每次在出现的东西上在B上调用它.这是

Call it on B, on the thing that presented, every time. This is

  • 减少混乱,因为您的出席和解雇将在同一地点,并且

  • less confusing, since your present and dismiss will be in the same place, and

    更有前途的证明,因为在将来的某个时候,您可能会让C出现另一个视图控制器(D),然后解雇会突然中断(它将突然开始解雇D,而不是解散自己) .

    more future proof, since at some point in the future you may make C present yet another view controller (D), and then the dismissal would suddenly break (it would suddenly start dismissing D, rather than dismissing itself).

  • 更多推荐

    我应该在呈现模式的UIViewController或UIViewController上调用dismissViewController吗?

    本文发布于:2023-10-27 18:27:25,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1534179.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:模式   UIViewController   dismissViewController

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!