Add navigationcontroller to detail view in splitview
I am following this example: http://doronkatz.com/ipad-programming-tutorial-hello-world. This example works great.
Now i want 3 tabs in the splitview and for each tab a new navigationcontroller. But i don't know how to implement it. I go to this code:
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];
// Update the view.
navigationBar.topItem.title = detailItem;
if ([detailItem isEqualToString:@"Test"]) {
TestViewController *testViewController = [[TestViewController alloc] initWithNibName:@"TestView" bundle:nil];
[self.navigationController pushViewController:testViewController animated:NO];
[mapViewController release];
}
if ([detailItem isEqualToString:@"Test2"]) {
}
}
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
}
But i know that i actually don't have to use 'pushviewcontroller', i just want a new navigationcontroller starting from that point, and so for each tab in the s开发者_运维百科plitview. How can i accomplish this? I know it's really basic, but i cant figure it out.
Thanks.
As I understand your requirement, you want a split view controller as the main controller. The left panel will select an item and the right detail view for that item will contain 3 tabs. Each tab will have a navigation controller. The app store follows a pattern similar to the detail view.
Its important to structure your controllers as a tree.
- root: split view controller
- list view: table controller (MasterViewController for selecting fruit)
- detail view: tab controller (all info about watermelon)
- tab1: navigation controller
- page 1: first tab root controller (history of watermelons)
- tab2: navigation controller
- page 1: first tab root controller (map of watermelon farms)
- tab3: navigation controller
- page3: first tab root controller (watermelon recipes)
- tab1: navigation controller
With this pattern you can create the controller structure on viewDidLoad, but then change the contents of page 1, 2, 3 when responding to setDetailItem UINavigatorContoller has a popToRootViewControllerAnimated message that can reset the previous navigation controller stack for each of the 3 navigation controllers. When I started learning ios development, I found setting up the controller hierarchies in code easier than using interface builder. IB is faster once you get the concepts. You can still create an IB nib controller for page1,2,3 root view controllers.
good reference: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457
If I understand you correctly, you have a UISplitViewController, and you wish to have three UINavigationControllers as detail views. In which case, the following will work if implemented in your UISplitViewController class:
if ([detailItem isEqualToString:@"Test"]) {
TestViewController *testViewController = [[TestViewController alloc] initWithNibName:@"TestView" bundle:nil];
//since self.viewControllers is immutable, let's make our own temporary copy.
NSMutableArray *tempArray = [self.viewControllers mutableCopy];
//switcheroo with the new view controller
[tempArray replaceObjectAtIndex:1 withObject:testViewController];
// our new view controller is retained by the array, so let's release it
[testViewController release];
//set the new array to be displayed
self.viewControllers = tempArray;
//clean up - out mutableCopy returns a retained object
[tempArray release];
}
精彩评论