【问题标题】:UINavigationController with UITabViewControllerUINavigationController 与 UITabViewController
【发布时间】:2011-10-26 15:25:31
【问题描述】:

我正在构建一个应用程序,它的委托具有 UINavigationController (navigationController)。第一个视图是一个 UITabViewController (tabView),它有一个 UINavigationController 和一个 UIViewController 和一个 UITableView,它显示了一些联系人。

我想要做的是在点击表格视图中的联系人时(在最顶部的导航控制器上)推送一个带有联系人信息的新视图控制器

我在 appDelegate 中执行以下操作:

[self.window makeKeyAndVisible];
[self.window addSubview:[navigationController view]];
TabsView *tabsView = [[TabsView alloc] initWithNibName:nil bundle:nil];
[navigationController.view addSubview:[tabsView view]];

tabsView 的第一个选项卡加载 ContactsView.m,它有一个包含所有联系人的 UINavigationController,当有人点击一行时,它应该像这样推送新视图:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [table deselectRowAtIndexPath:indexPath animated:YES];
    ContactSecondView * varContactSecondView = [[ContactSecondView alloc] initWithNibName:nil bundle:nil];
    varContactSecondView.title = [[contactsArray objectAtIndex:indexPath.row] name];
    [self.navigationController pushViewController:varContactSecondView animated:YES];
    [varContactMapView release];
}

但是连续触摸时没有任何反应。

所以我有不同的文件:使用 UINavigationController

应该如何访问委托的navigationController?我做得对吗?

编辑:如果这提供了任何线索,当我在 ContactsView.m 中执行 self.navigationController.title = @"Contacts"; 时,它不会更改顶部栏的标题。

谢谢!

【问题讨论】:

    标签: ios uinavigationcontroller pushviewcontroller uitabview


    【解决方案1】:

    两件事。

    1. 不建议在导航控制器中嵌入UITabBarController。可以在 UITabBarController 中嵌入 UINavigationController。我知道将 UITabBarController 嵌入到 UINavigationController 中会是一个“不错的选择”,但您可能需要重新考虑您的设计,以便遵循 iOS 设计理念。

    2. 不要将子视图添加到 appDelegate 中的窗口,而是尝试将您正在使用的控制器添加到窗口的 rootViewController 属性,即

      self.window.rootViewController=navigationController;

    【讨论】:

    • 嗨蒂姆。好吧,问题在于选项卡使“内容视图”更小,这就是将 uitabview 放入 uinavigationcontroller 的想法。假设如何这样做?第二点还没有解决问题:(谢谢!
    • 第二点解决不了任何问题,只是正确的处事方式。
    • 好的。忘记导航控制器。如果我在 tabviewcontroller 中有一个 navController。推送uiviewcontroller时是否有机会隐藏标签栏?我读过“hidesBottomBarWhenPushed”,但我不知道具体放在哪里。
    【解决方案2】:

    我可能错了,但我认为您没有使用正确的方式在导航控制器中设置视图控制器。

    你会的:

    [navigationController.view addSubview:[tabsView view]];
    

    我会使用:

    [navigationController setViewControllers:[NSArray arrayWithObject:tabsView] animated:NO];
    

    【讨论】:

    • 好吧,我用你的代码更改了我的代码,但这并没有解决我的问题。它仍然没有推动新的 ViewController :/ didSelectedRowAtIndexPath 有什么?还是谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 2011-08-15
    相关资源
    最近更新 更多