'Tried to pop to a view controller that doesn't exist.'

前端 未结 11 787
清酒与你
清酒与你 2021-02-05 12:13

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

-(IBAction)dismissView
{
    RootViewController *rootController = [[RootViewC         


        
11条回答
  •  礼貌的吻别
    2021-02-05 12:54

    The UINavigationController has a stack of ViewControllers which is stored in the viewControllers(NSArray) property. Enumerate to the required ViewController and pop to that ViewController.

    Following code should solve the problem.

    -(IBAction)dismissView
    {
        NSArray *array = self.navigationController.viewControllers;
        for (id controller in array) {
            if ([controller isKindOfClass:[RootViewController class]]) {
                [self.navigationController popToViewController:controller animated:YES];
    
            }
        }
    }
    

提交回复
热议问题