【问题标题】:Why is my UIViewController not used as the presentingViewController, although its presentedViewController property gets set?为什么我的 UIViewController 没有用作presentingViewController,尽管它的presentedViewController 属性已设置?
【发布时间】:2012-03-20 19:39:06
【问题描述】:

iOS iPad 模拟器 5.0.1 上的设置:

根控制器 X、UIViewController A、UIViewController B

A.definesPresentationContext = YES;
// Skipped: set modal presentation props.
[A presentViewController: B, animated: YES, completion: nil];

如果我检查A.presentedViewController,结果是B - 正确。 如果我检查B.presentingViewController,结果是X

这怎么可能?如果 B 被解雇,这也会导致我在 A 中得不到通知的问题(我在 A 中覆盖 dismissViewController: )。

我需要做什么来制作演示控制器?

【问题讨论】:

    标签: objective-c cocoa-touch ios5 uiviewcontroller xamarin.ios


    【解决方案1】:

    Methods[A presentViewController: B, animated: YES, completion: nil];将controller B呈现为Modal,所有modals都从rootViewController呈现,因此presentingViewController为X。

    如果您想在 A 中知道 B 何时被解雇,您必须在 B 的 viewDidDisappear 中触发 NSNotification 以便 A 可以捕获该通知

    【讨论】:

    • 这是 iOS5 的新功能吗?我不记得所有模式都是从根目录呈现的。
    • 我相信对于 iPhone 来说这一直是一样的,对于 iPad 来说一切都应该如你所说!
    • 我在 iPad 上。现在它始终是根控制器。让我们等待其他建议,我现在很困惑。
    • 您是否尝试过添加B.modalPresentationStyle = UIModalPresentationCurrentContext;并保留A.definesPresentationContext = YES;
    • 是的,然后它正在工作,但是控制器不再以模态方式呈现,而是作为当前控制器的子控制器。
    猜你喜欢
    • 1970-01-01
    • 2013-05-11
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    相关资源
    最近更新 更多