I have an application with based of UITabBarController, and inside one of the tabs I have UITableViewController to display "products", till here everything is working perfectly.
Now I want when clicking one of the cells inside the UITableViewController to open a UINavigationController to display UIViewController with details of that product.
I think the application hierarchy should be like the following:
UITabBarController (BASE) Level-1
|
|___ UITableViewController (PRODUCTS) Level-2
|
|___ UINavigationController Level-3
|
|___ UIViewController (PRODUCT DETAILS) Level-4
How to achieve Level-3 and Level-4?
Thanks in advance :)
Just watch this tutorial. http://www.youtube.com/watch?v=LBnPfAtswgw
First You Will need to reset your hierarchy to something like this:
UITabBarController (BASE)
|
|___ UINavigationController
|
|___ UITableViewController (PRODUCTS)
|
|___ UIViewController (PRODUCT DETAILS)
You need to add a UINavigationController in the TabBarController, then you will use it to push the Product Detail.
to add a UINavigation on TabBarController:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
UINavigationController *tableNavController_1 = [[[UINavigationController alloc] initWithRootViewController:YourProductViewController_1] autorelease];
UINavigationController *table2NavController_2 = [[[UINavigationController alloc] initWithRootViewController:YourProductViewController_2] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController_1, table2NavController_2, nil];
//then add the controller to view like,
// this:
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
//or this:
[self.view addSubview:tabBarController.view];
I recommend you to create a new UITableViewController for each ProductViewController and then use the delegate method: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
for pushing the detail view:
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"Nib name" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES]
[detailViewController release];
来源:https://stackoverflow.com/questions/6731003/create-uinavigationcontroller-in-uitableviewcontroller-inside-uitabbarcontroller