【问题标题】:Push a UIViewController within a UITabBarController's UINavigationController在 UITabBarController 的 UINavigationController 中推送 UIViewController
【发布时间】:2015-01-20 17:42:40
【问题描述】:

我有一个带有 4 个选项卡的 UITabBarController。每个选项卡都是一个 UINavigationController,其中 UIViewController 作为其 RootViewController 加载。 例如:

Tab1ViewController* viewC = [[Tab1ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController* navCDisc = [[UINavigationController alloc] initWithRootViewController: viewC];

点击我的 Tab1ViewController 中的一个按钮,我现在必须在现有的 UIViewController 之上推送一个新的 UIViewController。我怎样才能做到这一点?

在 Tab1ViewController.m 文件中,我尝试了:

UIViewController *newVC = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newVC];
[self.navigationController pushViewController:newVC animated:YES];

这行为很奇怪,会自动切换选项卡。

【问题讨论】:

    标签: objective-c uiviewcontroller uinavigationcontroller uitabbarcontroller


    【解决方案1】:
    UIViewController *newVC = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    [self.navigationController pushViewController:newVC animated:YES];
    

    仅此而已,不要创建另一个 UINavigationController。如果它不起作用,请确保代码已执行并且 self.navigationController 不是 nil(放置断点);如果是,它将起作用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      相关资源
      最近更新 更多