Quote:
Originally Posted by jmktayag
Can you further discuss how to use addChildViewController? Can I also present it in a modal view?
|
I've done a project using child view controllers. It's cool. The introduction to the UIViewController class has a pretty good discussion of the new container view controller feature of iOS 5. That's all I needed in order to make it work, and I got it working the first time, without having to fiddle with it. I found it clean and easy to use.
In iOS 5, a view controller can manage one or more child view controllers, who's content view(s) become subviews of their parent view controller.
The addChildViewController call tells the parent view controller about the child view controller. You add all the child view controllers that the parent will ever manage, before ever displaying any of them. That method doesn't actually do anything visible.
Once you add a view controller as a child view controller, you can install the child view controller's content view as a subview of the parent view controller.
The method transitionFromViewController:toViewController:dura tion

ptions:animations:completion: is the workhorse method that lets you switch child view controllers. That method lets you build your own parent view controller that acts like a navigation controller, tab controller, or create a novel type of container controller.
What I did was to set up a parent view controller that had subviews that were laid out to contain child view controllers. I created a tab bar like view that went across the bottom. Above that was a view to hold a "content view". I wrote a method showContentViewAtIndex:withTransition: that took an index to a child view controller and swaps it into place with one of several transitions. That method was very easy to write using the new transitionFromViewController:toViewController:dura tion

ptions:animations:completion: method.
There's also a method automaticallyForwardAppearanceAndRotationMethodsTo ChildViewControllers, that if you make it return TRUE, causes the system to forward rotation and other appearance changes to child view controllers.
It shouldn't be too hard to create a custom modal view controller facility in your app's view controllers. You'd create a new parent class for "normal" view controllers, and have it accept a view controller that you wanted to display modally and make it a child. You could then implement a modal transition. You would need to add a partly transparent overlay over the rest of the view controller's content to prevent the user from clicking on something until dismissing the "modal" view controller.
The code I wrote is under NDA, and tightly entwined with that project, so I can't really share it.