【问题标题】:self.navigationController pushViewController not workingself.navigationController pushViewController 不工作
【发布时间】:2011-05-28 21:44:18
【问题描述】:

我有一个带有单个 UIViewController 的 View 应用程序。然后我通过 IB 添加UITableViewController,并尝试通过在UIViewController(我的主视图)中按下按钮来显示UITableViewController。我的按钮按下 (IBAction) 包含以下代码,我试图通过这些代码推送我的 UITableViewController 视图并显示它:

DataViewController *dataController = [[DataViewController alloc] initWithNibName: @"DataViewController" bundle:nil];
[self.navigationController pushViewController:dataController animated:YES];
[dataController release];

我的DataViewController 根本没有被推入堆栈并显示, 我还检查了上面的代码,self.navigationController=nil 大概这就是问题的根源。如果有,如何改正?

请帮忙。

【问题讨论】:

    标签: iphone ios ios4


    【解决方案1】:
    UINavigationController *navCtrlr = [[UINavigationController alloc]initWithRootViewController:yourfirstviewController];
    [self.window setRootViewController:navCtrlr];
    navCtrlr.delegate = self;
    navCtrlr.navigationBarHidden = YES;
    

    appdelegate.m 中创建导航控制器,然后您可以导航到任何uiviewcontroller

    【讨论】:

      【解决方案2】:

      您需要实际创建一个UINavigationControllernavigationController 属性告诉您您的 DataViewController 当前是否在 UINavigationController 的层次结构中;如果不是(在本例中),navigationController 属性将返回 nil

      【讨论】:

      • 如果我在上面的设计中正确理解了你,我需要有一个 UINavigationController 来代替 UITableViewController,然后从 IB 添加一个 UITableView。但是在这种方法中,我如何能够滑入我的 UINavigationController(通过我的 UIViewController 按下按钮)?我在这里有点困惑。你能解释一下如何去做吗?我的目标是通过在我的主 UIViewController 视图中按下按钮来显示 UITableViewController。这里的正确方法应该是什么?再次感谢。
      • UINavigationController 是一个“控制器中的控制器”,它旨在让您可以推送和弹出控制器并管理视图层次结构。您可能需要观看Stanford University "iTunes U" podcast 的第 6 课和第 7 课,以深入了解如何在您的应用中使用UINavigationController
      猜你喜欢
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-02
      • 2011-09-29
      相关资源
      最近更新 更多