iPhone - 嵌套视图和控制器
是否可以有一个 iPhone 屏幕,其视图由该屏幕的 UIViewController 从 xib 加载,但该屏幕内的另一个 UIView 的内容从单独的 xib 文件加载?如果是这样,是否可以让嵌套视图的事件由屏幕其余部分的单独自定义 UIViewController 子类处理?如果这两件事都可能的话,它们是否也是可取的?
Is it possible to have a single iPhone screen with its view loaded from a xib by that screen's UIViewController, but then another UIView within that screen with content loaded from a separate xib file? If so, is it possible to have that nested view's events handled by a separate custom UIViewController subclass from the rest of the screen? If both of these things are possible, are they also advisable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的。 Apple 建议不要同时在屏幕上激活多个 UIViewController,因此他们会建议不要这样做。我建议仅当第二个视图控制器的原因是导航或模式时才这样做。
旨在加载其他视图控制器(例如导航控制器)的视图控制器本身需要一些屏幕空间,并使用剩余的屏幕空间来加载另一个视图控制器。那很好。这里的标准是只有一个控制器呈现内容,而另一个控制器呈现导航。
视图控制器可以加载另一个视图控制器来执行一些有限的任务,例如从列表中选择一个项目或输入一些文本。第二个视图控制器可能只填充屏幕的一部分。这里的标准是一个控制器的行为是模态的,并且只会显示足够长的时间以获得一些用户输入。
对于在两个呈现内容的视图控制器之间分割屏幕的一般情况,Apple 建议您使用从 UIViewController 派生的单个类来管理视图。如果视图足够复杂,需要其他控制器,则从 NSObject 派生它们,并让主视图控制器管理子控制器以及视图。子控制器将主控制器作为委托,主控制器将视图传递给子控制器进行管理,但不拥有。
It is possible. Apple suggests against having more than one UIViewController active on screen at once, so they would advise against. I would suggest only doing it if the reason for the second view controller is navigation or modal.
A view controller with the purpose of loading other view controllers, like a navigation controller, needs some screen space for itself and uses the rest to load another view controller. That is fine. The criteria here is that only one controller is presenting content while the other is presenting navigation.
A view controller could load another view controller to perform some limited task like selecting an item from a list or entering some text. The second view controller might only fill part of the screen. The criteria here is that the one controller behaves modally and will only be displayed long enough to get some user input.
As for the general case of splitting the screen between two view controllers that are presenting content, the Apple suggestion is that you have a single class derived from UIViewController manage the views. If the view is complex enough to warrant other controllers, then derive them from NSObject and have the master view controller manage the child controllers along with the views. The child controllers would have the master controller as a delegate, and the master controller would pass views to the child controllers to manage but not own.