Ios – nested push animation can result in corrupted navigation bar PUSH POP PUSH

iosiphone

I have three Controller First, Second, Third. First is the rootViewController of navigationController.

in SecondViewController, I have protocol called SecondViewControllerDelegate which has a delegate method

@protocol SecondViewControllerDelegate <NSObject>

- (void)doneSucceed:(NSString *)msg;

@end

in FirstViewController, I have a button, when click it, doing the following

[self.navigationController pushViewController:_s animated:YES];

_s means the SecondViewController whose delegate is the FirstViewController

in doneSucceed method do the following

- (void)doneSucceed:(NSString *)msg
{
    NSLog(@"%@", msg);
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController pushViewController:_t animated:YES];
}

then the error

nested push animation can result in corrupted navigation bar
show, anyone tell me why? THX

Best Answer

The problem is you are calling pop and push with animation back to back. In iOS6 the push call is basically ignored but in iOS7 the push is called while the pop is being animated hence they are "nested" and you get the following:

nested push animation can result in corrupted navigation bar show

Instead of popping inside doneSucceed you can make the pop call from the SecondViewController. Then wait for the FirstViewController's viewDidAppear to push the ThirdViewController. You can use the doneSucceed method as a way toggle whether or not you should transition to the ThirdViewController on viewDidAppear

Related Topic