self.navigationController pushViewController not working

杀马特。学长 韩版系。学妹 提交于 2019-12-22 03:52:21

问题


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:

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?

Please help.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/6164525/self-navigationcontroller-pushviewcontroller-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!