popViewController not working in iOS 9

1.1k Views Asked by At

I have inherited my ViewController from BaseViewController and I have pushed my SecondViewController using storyboard ID.but, when I am trying to popview from second view to view controller its not working. Here is my code:

dispatch_async(dispatch_get_main_queue(), ^{
                [self showMesssgeonAlert:@"Success"];
                [self hideProgress];
                [self.navigationController popViewControllerAnimated:TRUE];
            });

Even i tried with :

NSArray *controllerArray = self.navigationController.viewControllers;

for (id controller in controllerArray)
{
    if ([controller isKindOfClass:[ViewController class]])
    {
[self.navigationController popViewControllerAnimated:TRUE];
    }
}

but,its not working in both the conditions.What should I do?Please help me.

4

There are 4 best solutions below

0
On

Try using appDelegates navigation controller so, try as follow:

dispatch_async(dispatch_get_main_queue(), ^{
                [self showMesssgeonAlert:@"Success"];
                [self hideProgress];
                [((AppDelegate*)[[UIApplication sharedApplication]delegate]).navigationController popViewControllerAnimated:TRUE];
            });
0
On

Make sure you are pushing the controller SecondViewController on ViewController, If you are using segue then check the show type like (Push, Present Modally). If this is correct then check the navigation controller object, it should have an object.

Finally check the memory address of navigation controller in both the view controllers did load method. It should same.

2
On

You should double check:

  1. Both the view controllers should be on same navigation controller stack.

  2. I guess, second view controller is on different navigation controller.

  3. How you're pushing to second view controller?

0
On

Split view controller may cause this issue, in my case, I removed it, and popViewController started working.