开发者

iPhone - error loading view controller

开发者 https://www.devze.com 2023-01-07 15:11 出处:网络
I load view controllers all the time in the following format: -(void)loadSelectUser { MyViewController *nextController = [[MyViewController alloc] initWithStyle:UITableViewStyleGrouped];

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.navig开发者_开发知识库ationController 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消