views:

27

answers:

1

I load view controllers all the time in the following format:

-(void)loadSelectUser {
    MyViewController *nextController = [[MyViewController alloc] initWithStyle:UITableViewStyleGrouped];

    MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    [delegate.navigationController pushViewController:nextController animated:YES];
    [nextController release];   
}

And I've never had an issue with that. But right now I'm dealing with the issue that the next view doesn't load completely. The navigation bar shows up and the viewDidLoad and the numberOfSectionsInTableView methods are both called. That is it. The table doesn't show up, it still shows the previous view.

I imagine this means there is a memory leak or something not connected properly. Is this the right path to be looking? If so, what is your best suggestion for debugging this issue. My code has no error messages so I'm not sure where to start. I load the view properly in a different controller, but for some reason it doesn't do it after this particular view*.

*This view happens to do a lot data manipulation with downloading objects, saving them and such. But again, it looks like it is all working properly. What would mess up the navigation controller loading the next view completely?

Oh, and just to mess things up more, some times, it works properly. But I run it one more time and it doesn't do it again.

Update: TechZen comment about the proper way to push a new view controller seemed to help a little. There is a higher rate of it working, unless I am pushing a tableviewcontroller. Depending on the action my view will push a UITableViewController or a UIViewController with a nib file. The second usually (not always) works.

Also, in a different view I am adding a modal view. But when I try to dismiss it using [self dismissModalViewControllerAnimated:YES]; it doesn't always work. Again it's hit or miss on it. Anyone have an idea of what would be causing the transition of windows to be finicky?

+2  A: 

Calling the app delegate to get the navigation controller is unnecessary and risky. Any view controller on a navigation controller stack has a populated navigationController property so you can just use self.navigationController.

It's risky to call the app delegate's navigation controller because you have no guarantee that you will get the same navigation controller as the one that currently holds the view controller calling the push. You could in theory end up with two overlapping and conflict navigation controllers.

Switch the code to self.navigationController and see if that fixes the problem.

TechZen
Wow. I wish I had known that before. But I'm so thankful for learning it now. It solved it right away. Thank you!
RyanJM
I guess I spoke too soon. It worked the first time I tried it, but it isn't working. It still randomly works.
RyanJM