'Tried to pop to a view controller that doesn&

2019-03-18 13:02发布

I am getting this error when I call my method dismissView. Here is the method stub:

-(IBAction)dismissView
{
    RootViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    [self.navigationController popToViewController:rootController animated:YES];
}

That should work, and I've checked, rootController is initialized and allocated. Any ideas?

8条回答
乱世女痞
2楼-- · 2019-03-18 13:38

The -popToViewController is used to pop view controllers OFF the stack, down to one that already exists. Your UINavigationController has a stack of ViewControllers (stored in the viewControllers property), when you popToViewController, you're going to want to pass one of the elements in that array as the first argument.

What you most likely want to do in this case is use -popViewControllerAnimated:, which will remove the top ViewController from the stack

查看更多
爷的心禁止访问
3楼-- · 2019-03-18 13:39

I resolved this by using pushViewController rather than popToViewController

查看更多
登录 后发表回答