ios self.navigationController pushViewController 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6164525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
self.navigationController pushViewController not working
提问by XMarshall
I have a View application with a Single UIViewController
. I then add a UITableViewController
through the IB, and I am trying to display the UITableViewController
through a button press in the UIViewController
(my main view). My button press (IBAction) contains the following code through which I am trying to push my UITableViewController
view and display it:
我有一个带有 Single 的 View 应用程序UIViewController
。然后我UITableViewController
通过 IB添加一个,并且我试图UITableViewController
在UIViewController
(我的主视图)中显示通过按钮按下。我的按钮按下 (IBAction) 包含以下代码,我试图通过这些代码推送我的UITableViewController
视图并显示它:
DataViewController *dataController = [[DataViewController alloc] initWithNibName: @"DataViewController" bundle:nil];
[self.navigationController pushViewController:dataController animated:YES];
[dataController release];
My DataViewController
is not at all getting pushed into the stack and displayed,
Also I have checked that in the code above, self.navigationController=nil
Probably this is the source of the problem. If so, how to rectify it?
我的DataViewController
根本没有被推入堆栈并显示出来,而且我已经在上面的代码中检查过,这self.navigationController=nil
可能是问题的根源。如果是,如何纠正?
Please help.
请帮忙。
回答by Sreejith
UINavigationController *navCtrlr = [[UINavigationController alloc]initWithRootViewController:yourfirstviewController];
[self.window setRootViewController:navCtrlr];
navCtrlr.delegate = self;
navCtrlr.navigationBarHidden = YES;
Create navigation controller in appdelegate.m
then you can navigate to any uiviewcontroller
在其中创建导航控制器,appdelegate.m
然后您可以导航到任何uiviewcontroller
回答by Scott Forbes
You need to actually create a UINavigationController
. The navigationController
property tells you whether your DataViewController is currently in a UINavigationController
's hierarchy; if not (as in this case), the navigationController
property returns nil
.
您需要实际创建一个UINavigationController
. 该navigationController
属性告诉您您的 DataViewController 当前是否在 aUINavigationController
的层次结构中;如果不是(在这种情况下),则该navigationController
属性返回nil
。