在应用程序中处理不同的视图控制器:在创建自定义内容视图控制器 [英] Handle different view controllers within an application: creating Custom Content View Controllers
问题描述
在应用程序开发我有问题,支持正确的应用程序架构。这是我目前正在开发的应用程序如此。特别是,我需要支持像下面的架构。
During application development I have problems to support the right application architecture. This is true for the application I'm currently developing. In particular, I need to support an architecture like the following.
正如你所看到的, MainViewController
是应用程序的主控制器,并具有对应用程序生命周期内管理不同的控制器。在这种情况下 MainController
是一种集中式控制器(其视图的子视图始终保持在前面,认为它作为一个菜单视图)用于管理应用程序的不同状态(例如LOGIN_AREA,HOME_AREA,等)。
As you can see, the MainViewController
is the main controller for the application and has to manage different controllers within the application lifecycle. In this case MainController
is a sort of centralized controller (a subview of its view stays always on front, think to it as a menu view) that manages the different states of the application (e.g. LOGIN_AREA, HOME_AREA, etc.).
在下面我写了一些代价来实现上述架构。
In the following I wrote some consideration to achieve the above architecture.
由于 MainViewController
需要总是在其他视图前面,以显示其视图的子视图( UIviewControllerX
的意见)我将其设置为 RootViewController的
。
Since MainViewController
needs always to display its view's subview in front of other views (UIviewControllerX
's views), I set it as the rootViewController
.
由于 MainViewController
已经由其他控制器被访问(例如 UIViewControllers1
),他们需要有一个(弱)引用它。
Since MainViewController
has to be accessed by the other controllers (e.g UIViewControllers1
), they need to have a (weak) reference it.
MainViewController
有权管理应用程序状态的公共方法。它存储当前的控制器,并添加到其视图所选控制器视图作为其子视图。例如:
MainViewController
has a public method to manage the application state. It store the current controller and add to its view the selected controller view as its subview. For example:
- (void)manageController
{
if(currentState == LOGIN_AREA)
{
self.currentController = [[[LoginViewController alloc] init] autorelease];
}
// other stuff here...
[self.view addSubView:self.currentController.view];
}
上面的图案似乎工作,但我不pretty知道这是否会是正确的。在网瘾,情况就变得复杂,如果的UIViewController
(如 UIViewController1
)必须有一个 UINavigationController的
。
我读过<一个href=\"https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html\"相对=nofollow>视图控制器编程指南适用于iOS 。特别是,我发现有趣的部分<一个href=\"https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP40007457-CH101-SW1\"相对=nofollow>创建,但我还没有自定义内容视图控制器发现任何实际的例子来创建自定义的。
I've read the View Controller Programming Guide for iOS. In particular, I found interesting the section Creating Custom Content View Controllers but I havent' found any example to create a customized one.
所以,我的问题是以下几点。
So, my question is the following.
你能不能给我点建议,以实现以下架构?或者,你能给我一些提示,以开发自定义的内容视图控制器?
Could you give me suggestions to achieve the following architecture? Or could you give me some tips to develop a custom content view controller?
感谢您提前。
推荐答案
对于那些有兴趣
要实施类似的机理有两种不同的方式。
To implement a similar machanism there are two different ways.
1)实现自定义内容容器。这是一个复杂的任务,但它是可能的。欲了解更多信息请参阅书写高品质-view控制器
1) Implement a custom content container. It's a complex task but it's possible. For more info read writing-high-quality-view-controller
2)使用新的iOS 5的API。欲了解更多信息它是可以读实现一个容器视图控制器在<节href=\"https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html\"相对=nofollow> UIViewController类参考。
2) Use the new iOS 5 API. For more info it's possible to read Implementing a Container View Controller section in UIViewController Class Reference.
希望它帮助。
这篇关于在应用程序中处理不同的视图控制器:在创建自定义内容视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!