我有一个像这样的 View 层次结构:
- 从应用委托(delegate)中显示的自定义 View Controller (例如 View Controller 1)。
- 另一个 View Controller (例如 View Controller 2)从 View Controller 1 中以模态方式显示。
- 另一个 View Controller (例如 View Controller 3)从 View Controller 2 中以模态方式显示。
- 还有一个 View Controller (例如 View Controller 4),我需要从中执行步骤 2 和 3。
现在,在某些事件中,我需要取消整个模态视图层次结构。所以我正在做的是,我从 View Controller 3 发送有关该事件的通知,并在 View Controller 中监听该通知,然后执行:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"cancelViews" object:nil];
这可行,但有一个问题。根据我的应用程序流程,我最终在 View Controller 1 和 View Controller 4 上注册此通知。现在,当 View Controller 1 的整个模式层次结构启动并且通知由 VC1 注册,然后在另一个 View 层次结构之上注册时显示了 View Controller 4,最后当引发通知时,我的 View 层次结构都消失了。
我只希望最顶层的 View 层次结构消失。任何解决方案都会真正有帮助。
最佳答案
如果这不是您想要采取的路线(尽管我强烈鼓励您这样做),您可以设置 1 和 4 View Controller 来发布 Root View Controller 将监听的不同事件。
关于iphone - 消除模态视图层次结构——一个优雅的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5767665/