在 UITabBarController 内的 UITableViewController 中创建 UINavigationController

发布于 2024-11-24 21:37:56 字数 605 浏览 2 评论 0原文

我有一个基于 UITabBarController 的应用程序,在其中一个选项卡中我有 UITableViewController 来显示“产品”,直到这里一切都工作正常。

现在,我希望当单击 UITableViewController 内的一个单元格时打开 UINavigationController 以显示带有该产品详细信息的 UIViewController

我认为应用层次结构应该是这样的:

UITabBarController (BASE) Level-1
  |
  |___ UITableViewController (PRODUCTS) Level-2
         |
         |___ UINavigationController Level-3
                |
                |___ UIViewController (PRODUCT DETAILS) Level-4

如何实现Level-3和Level-4?

提前致谢 :)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2024-12-01 21:37:56

首先,您需要将层次结构重置为如下所示:

UITabBarController (BASE)
  |
  |___ UINavigationController
      |
      |___ UITableViewController (PRODUCTS)
        |
        |___ UIViewController (PRODUCT DETAILS)

您需要在 TabBarController 中添加 UINavigationController,然后使用它来推送产品详细信息。

在 TabBarController 上添加 UINavigation:

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];

我建议您为每个 ProductViewController 创建一个新的 UITableViewController,然后使用委托方法:- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 用于推送详细信息视图:

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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文