一次在屏幕上显示多个视图控制器? [英] Multiple view controllers on screen at once?

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

问题描述

我正在尝试用 Cocoa Touch 中的控制器来解决问题.主要问题是我希望同时在屏幕上"有多个控制器——我想要一个大视图(带有控制器 A),由它们自己的控制器(比如 B)控制的较小视图组成.我想要这样,因为除法使代码更清晰.不好的是,额外的控制器(类型 B)不是屏幕上的一等公民",例如它们不会收到自动旋转查询和通知.(并且不能轻易显示模态控制器,他们必须将 presentModal... 消息发送到他们的父控制器.)

从 Cocoa 的角度来看,A 和 B 控制器之间有什么区别?系统是否保留某种指向最前面的控制器"的指针,它是一个向其发送通知之类的特权控制器?为什么其他控制器不接收它们,即使它们的视图在屏幕上?屏幕上"有多个控制器是否被认为是一种黑客行为?或者它是否受支持而我只是遗漏了某些点?谢谢.

<小时>

更多关于我试图解决的问题:我正在编写一个简单的照片浏览器.照片全屏显示,用户可以向左或向右滑动更改照片.A 控制器负责滚动部分,B 控制器负责每张照片本身.

隔离 B 似乎是个好主意,因为照片是从网络加载的,而且可能会发生很多事情,比如网络可能会宕机等等.在 B 控制器中,代码相当简单,因为 B 只适用于一张特定的照片.如果我将代码移到 A 控制器,事情就会变得一团糟.

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

解决方案

自 iOS 5 以来,现在对这种方案有了一流的支持,称为控制器包含.

swift 控制器遏制

objc 控制器遏制.>

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.)

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.


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.

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.

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.

解决方案

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

swift controller containment

objc controller containment.

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

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