0

I am working on an app that has a TabView controller, and in each tab is a TabeView, I have the TableView delegate and dataSource set to the main ViewController of the Object. I use the following code to try and push a new ViewController to the NavigationController:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DonationsDataViewController *data = [self.storyboard instantiateViewControllerWithIdentifier:@"donationData"];
    //TODO set data to be passed;
    [self.navigationController pushViewController:data animated:YES];
    NSLog(@"Show donation details.");
}

The problem I am having is that the app does not crash, I get my Log of: Show Donation details., but it never pushed the ViewController, am I doing something wrong here? If so, what would be the appropriate path to take to fix the problem?

EDIT

See THIS for more information on the structure of the project. I am new to iOS and this is just a project to play around with and learn. The zipped project can be downloaded HERE.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • Can you describe how have you structured of your view controllers? – user427969 Nov 13 '12 at 21:55
  • Set a breakpoint at `NSLog(@"Show donation details.");`. Get details about `self.navigationController` and `data` by typing in console `po self.navigationController` and `po data`. See if it returns a valid object. – ninjaneer Nov 13 '12 at 21:59
  • Could you post the code for how you're setting up the UITabBarController? – Craig Siemens Nov 13 '12 at 22:05
  • See my edit for more details and the project files, I am not sure exactly what you are asking for, I am new to iOS... – Matt Clark Nov 13 '12 at 22:23

1 Answers1

1

Have you verified that the navigationController instance is not nil? Sending messages to instances that are nil is valid in Objective-C, unlike in C#/Java, where calling methods on instances that are null will throw an exception.

trydis
  • 3,905
  • 1
  • 26
  • 31
  • I added a check: if(self.navigationController != nil){ //My code } And now nothing is Logged, why is this nil? And how do I fix it? I am a bit of an iOS Dev Noob :/ – Matt Clark Nov 13 '12 at 21:55
  • Here's an example using Interface Builder: http://codenugget.org/how-to-embed-a-navigation-controller-inside-a – trydis Nov 13 '12 at 22:04
  • This didn't do what I needed :/ I edited my question to include the code and some more details. – Matt Clark Nov 13 '12 at 22:40
  • The problem is that your setting your view controllers directly as sub controllers of the tab controller. You should have the navigation controller as the sub controller of the tab controller and then set the view controller as the root view controller of the navigation controller. If that makes any sense :) It's explained in the link after the image containing "Can i haz navigation". – trydis Nov 13 '12 at 22:59
  • So as you said, everything was embedded into the TabController, and there was no navigation controller. I embedded everything into a NavigationController and it worked great. Thanks. – Matt Clark Nov 15 '12 at 13:38