屏幕上有多个视图控制器? [英] Multiple view controllers on screen at once?

查看:101
本文介绍了屏幕上有多个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试着把头围绕在Cocoa Touch的控制器上。主要问题是我希望同时在屏幕上显示多个控制器 - 我希望有一个大视图(控制器A)由他们自己的控制器控制的较小视图组成(比如说B)。我希望这样做,因为该部门使代码更清晰。更糟糕的是,附加控制器(B型)不是屏幕上的一等公民,例如他们没有收到自动轮询查询和通知。 (并且无法轻松显示模态控制器,他们必须将 presentModal ... 消息发送到其父控制器。)

I am trying to wrap my head around controllers in Cocoa Touch. The main problem is that I would like to have more than one controller "on screen" at once – I want to have a large view (with controller A) composed of smaller views controlled by their own controllers (say B). I’d like to have it this way because the division makes the code much cleaner. What’s bad is that the additional controllers (of type B) are not "first-class citizens" on the screen, for example they do not receive the autorotation queries and notifications. (And cannot easily display modal controllers, they have to send the presentModal… message to their parent controller.)

Cocoa观点的A和B控制器之间有什么区别?系统是否保留某种指向最前面的控制器的指针,这是一个特权的指针,它发送通知和这些东西?为什么其他控制器不接收它们,即使它们的视图在屏幕上?在屏幕上有多个控制器被认为是黑客?或者它是否受到支持,我只是错过了一些观点?谢谢。

What is the difference between the A and B controllers from Cocoa viewpoint? Does the system keep some kind of pointer to the "frontmost controller", a privileged one to which it sends notifications and such stuff? Why don’t the other controllers receive them, even though their views are on the screen? Is having multiple controllers "on screen" considered a hack? Or is it supported and I am just missing some point? Thank you.

关于我想解决的问题的更多信息:我正在编写一个简单的照片浏览器。照片以全屏显示,用户可以向左或向右滑动以更改照片。 A控制器负责滚动部分,B控制器自己处理每张照片。

More about the problem I am trying to solve: I am writing a simple photo browser. Photos are displayed in full screen, user can swipe left or right to change photos. The A controller takes care of the scrolling part and the B controllers take care of each photo itself.

隔离B似乎是一个好主意,因为照片是从网络加载的并且有很多可能发生的事情,比如网络可能会崩溃等等。在B控制器中,代码非常简单,因为B仅适用于一张特定的照片。如果我将代码移动到A控制器,事情会变得混乱。

Isolating B seemed like a good idea, since the photos are loaded from network and there is a lot that can happen, like the network might be down et cetera. In the B controller the code is fairly simple, since B only works with one particular photo. If I moved the code to the A controller, things would get messy.

我唯一不喜欢当前的解决方案是我必须手动解决B不是一流的控制者。我必须通过A到B手动传递一些调用,当B想要显示模态对话框时,它必须将 presentModal ... 发送给A.这很难看。

The only thing I don’t like about the current solution is that I have to manually work around B not being a "first-class" controller. I have to pass some calls manually through A to B and when B wants to display a modal dialog, it has to send the presentModal… to A. Which is ugly.

推荐答案

从iOS 5开始,这个场景现在有了一流的支持,它叫做控制器遏制

There is now a first-class support for this scenario since iOS 5, it’s called controller containment.

这篇关于屏幕上有多个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆