XMarshall
XMarshall

Reputation: 971

self.navigationController pushViewController not working

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.

Upvotes: 10

Views: 26217

Answers (2)

Sreejith
Sreejith

Reputation: 131

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

Upvotes: 13

Scott Forbes
Scott Forbes

Reputation: 7417

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.

Upvotes: 12

Related Questions