多视图控制器策略 [英] multiple view controllers strategy

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

问题描述

我正在创建一个具有大约20个不同视图控制器的应用程序,这些视图控制器被加载到单个容器视图中。有些视图有滑块和按钮,有些只有按钮。
有没有一种策略可以用于使用Objective C编码技术更好地构建视图控制器?

I am making an app that has about 20 different view controllers that are loaded into a single container view. Some of the views have sliders and buttons and some have only buttons. Is there a strategy I can use to make building the views controllers more inline with Objective C coding techniques?

目前我正在尝试将类似的方法组合到模型对象中,但在我太过介入之前,我想我会问是否有更好的方法。我也愿意做基础工作和研究,所以任何关键词指向我正确的方向都会有所帮助,即协议,代表等。

Currently I am trying to combine similar methods into model objects but before I get too involved I thought I'd ask if there is a better way. I'm also willing to do the groundwork and research so any keywords to point me in the right direction would help, i.e. protocols, delegates, etc.

推荐答案

我给你的主要建议是考虑这些视图对象中的每一个是否需要控制。考虑UIViewController就像视图和模型之间的委托一样。如果您不需要极端上下文切换(即将新视图推送到导航堆栈),那么是否真的建议让20个代表浮动?在大多数情况下,并非如此。 UIViewController在任何想象中都不是一个重物,但是如果你每次决定将新组件放到屏幕上时,它很快就会使你的代码库变得笨重而且很大。你是UIViewController的子类。

The main piece of advice I'd give you is to consider whether or not each one of those view objects needs to be controlled at all. Consider UIViewController like the delegate between the view and the model. If you don't need an extreme context switch (i.e. pushing a new view onto the navigation stack), then is it really advisable to have 20 delegates floating around? In most cases, not really. UIViewController is not a "heavy object" by any stretch of the imagination, but it can quickly make your codebase unwieldy and large if every time you decide to throw a new component onto the screen, you subclass UIViewController.

尝试将注意力集中在划分逻辑上以分别设置视图和控制器的实际职责(对模型更改,调度操作,更新视图做出反应)分别为UIView子类和UIViewController子类。如果你确实需要将视图的某些组件分开,因为它的逻辑根本不适合主视图控制器的职责类别,那么,只有这样,才适合新的视图控制器。

Try to focus your attention on dividing the logic to setup the view and the actual responsibilities of the controller (reacting to model changes, dispatching operations, updating the view) into a UIView subclass and a UIViewController subclass respectively. If you truly do need to keep some component of the view separate because its logic simply cannot fit under the main view controller's category of responsibilities, then, and only then, is a new view controller appropriate.

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

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