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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:08:16  来源:igfitidea点击:

self.navigationController pushViewController not working

iphoneiosios4

提问by XMarshall

I have a View application with a Single UIViewController. I then add a UITableViewControllerthrough the IB, and I am trying to display the UITableViewControllerthrough 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 UITableViewControllerview and display it:

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

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

My DataViewControlleris not at all getting pushed into the stack and displayed, Also I have checked that in the code above, self.navigationController=nilProbably 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.mthen you can navigate to any uiviewcontroller

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

回答by Scott Forbes

You need to actually create a UINavigationController. The navigationControllerproperty tells you whether your DataViewController is currently in a UINavigationController's hierarchy; if not (as in this case), the navigationControllerproperty returns nil.

您需要实际创建一个UINavigationController. 该navigationController属性告诉您您的 DataViewController 当前是否在 aUINavigationController的层次结构中;如果不是(在这种情况下),则该navigationController属性返回nil