Reputation: 33428
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.
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.
Since MainViewController
needs always to display its view's subview in front of other views (UIviewControllerX
's views), I set it as the rootViewController
.
Since MainViewController
has to be accessed by the other controllers (e.g UIViewControllers1
), they need to have a (weak) reference it.
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];
}
The above pattern seems to work but I'm not pretty sure if it could be correct. In addiction, the situation gets complicated if a UIViewController
(e.g. UIViewController1
) has to be a UINavigationController
.
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?
Upvotes: 1
Views: 1310
Reputation: 33428
For those interested in.
To implement a similar machanism there are two different ways.
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) Use the new iOS 5 API. For more info it's possible to read Implementing a Container View Controller section in UIViewController Class Reference.
Hope it helps.
Upvotes: 1