14

I am using following line of code:

[self.navigationController popViewControllerAnimated:YES];

But it is not behaving in ios 7 as it doing in ios 6.Some times it does not pop controller while we are pressing back button 2- 3 times in succession.
Resulting in abrupt behaviour in navigation bar and deallocating a controller but showing the same on ui .
So when we press anything on that controller it results to a crash since controller is already deallocated.

Basheer_CAD
  • 4,768
  • 22
  • 35
user3441955
  • 141
  • 1
  • 1
  • 3
  • I'm happy that I am not the only one this has happened to. iOS 7+ bug (just got it in iOS 8, too). The view is popped from the navigation stack, but not animated from the UI. Then it gets stuck there, since it's no longer a part of the stack! – Dandy Nov 30 '14 at 15:11

7 Answers7

9

Check if you're running the code on the UI thread

cynistersix
  • 1,215
  • 1
  • 16
  • 28
  • 2
    dispatch_async(dispatch_get_main_queue(), ^{ [(UINavigationController *)tabBarController.selectedViewController popToRootViewControllerAnimated:NO]; }); worked for me with a similar problem – GRW Mar 22 '15 at 21:24
7
[self.navigationController popToRootViewControllerAnimated:YES];

This method will navigate to the root of your navigationController.

You can check your viewController hierachy With following code.

    NSLog(@"%@",self.navigationController.viewControllers);
Sunny Shah
  • 12,687
  • 8
  • 45
  • 79
5

I resolved this problem with this way:

 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                                                     UINavigationController * nav = tabbarControl.selectedViewController;
                                                                     [nav.viewControllers objectAtIndex:0];
[nav setViewControllers:@[[nav.viewControllers objectAtIndex:0]] animated:NO];
                                                                tabbarControl.selectedIndex = 0;
 });

When you delay one second the view will pop from UI, then the view will pop from the navigation stack, I think is the problem of the animation serial.

Johan
  • 7,269
  • 1
  • 29
  • 45
user5672256
  • 51
  • 1
  • 1
0

Try this code for popup a view controller from navigation stack

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count -2] animated:YES];
Macrosoft-Dev
  • 2,137
  • 1
  • 8
  • 15
0

I had the same problem on iOS 8.

I solved by subclassing UINavigationController and adding this code:

- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.delegate = self;
}

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    return [super popViewControllerAnimated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
{
    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
}

I basically block all the user interactions during the pop animation. I know it's a dirty solution, but it's the only one that I found that solves the problem.

Dzamir
  • 145
  • 3
  • 6
0

I think that should be working without dispatch_async. I got to the same issue, but i got to know the reason.

We should check it if the current scene is assigned to a proper view controller name in the storyboard.(identity inspector -> class)

If you connect a button action to m file and then insert the name of the view controller, that is not working.

So, you should delete the connect, and you insert the proper view controller name, and then you should connect the action to m file again.

0

I created my project from master-detail template, that uses split view controller. In my case, removing the split view controller resolved this issue.

iOS Developer
  • 3,393
  • 2
  • 38
  • 56