Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

self.navigationController pushViewController not working

Tags:

ios

iphone

ios4

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.

like image 975
XMarshall Avatar asked May 28 '11 21:05

XMarshall


2 Answers

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

like image 72
Sreejith Avatar answered Oct 17 '22 22:10

Sreejith


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.

like image 34
Scott Forbes Avatar answered Oct 17 '22 22:10

Scott Forbes