Create UINavigationController in UITableViewController inside UITabBarController

走远了吗. 提交于 2019-12-08 05:49:02

问题


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 :)


回答1:


Just watch this tutorial. http://www.youtube.com/watch?v=LBnPfAtswgw




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!