1
votes

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

3

3 Answers

4
votes

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

1
votes

Assume navigation controller as a stack of viewcontrollers.

[self.navigationController popViewControllerAnimated:YES];

does pop the viewcontroller from the stack.Now that viewcontroller is not valid.And from that invalid viewcontroller you are calling

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

and hence as it is a stack the value is the middle is not valid and trying to push a value on top from the invalid middle value

If 1,2,3 are members of the stack,it is ok to remove 2 but the removed 2 is trying to add the 3 above 2 and since 2 is not already in stack 3 cannot be added properly

0
votes

There's also way to do the thing you want just by setting viewControllers property of navigationController

NSMutableArray* controllers = [[self.navigationController viewController] mutableCopy];
[controllers removeLastObject];
[controllers addObject:_t];
[self.navigationController setViewControllers:controllers animated:YES]