iPhone UINavigation Issue - nested push animation

2019-01-08 05:56发布

I keep getting the following errors:

2011-04-02 14:55:23.350 AppName[42430:207] nested push animation can result in corrupted navigation bar
2011-04-02 14:55:23.352 AppName[42430:207] nested push animation can result in corrupted navigation bar
2011-04-02 14:55:23.729 AppName[42430:207] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2011-04-02 14:55:23.729 AppName[42430:207] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

Here is what I am doing. From a view controller, I call the following when a certain button is pushed:

EventsViewController *viewController = [[EventsViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.navigationBar.tintColor = [UIColor blackColor];
[self presentModalViewController:navController animated:YES];
[viewController release];
[navController release];

Then, if a certain button is pushed in EventsController, I call:

SingleEventViewController *viewController = [[SingleEventViewController alloc] initWithEvent:[currentEvents objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];

Then, if a certain button is pushed in SingleEventViewController, I call:

EventMapView* viewController = [[EventMapView alloc] initWithCoordinates];
[[self navigationController] pushViewController:viewController animated:YES];
[viewController release];

So yea, it's obvious that there's nested push animations, but isn't this the right way to go about it? I checked out Apple's DrillDownSave code and this appears to be how they're doing it. Does it matter that I use init methods instead of viewDidLoad methods?

20条回答
甜甜的少女心
2楼-- · 2019-01-08 06:12

Just to complete the list, here is another reason which can cause "nested push animation can result in corrupted navigation bar":

I did setup several NavigationController within a TabBarController and set the selectedIndex within the storyboard Identifiy Properties. After moving active Tab to Code error disappeared.

查看更多
【Aperson】
3楼-- · 2019-01-08 06:14

My problem had to do with the keyboard being active.

This was caused for me by pushing a ViewController from a textField's delegate method:

-(void)textFieldDidBeginEditing:(UITextField *)textField{

        FilterLocationViewController *destViewController = (FilterLocationViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"FilterLocationViewController"];

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

}

By changing the code to this:

-(void)textFieldDidBeginEditing:(UITextField *)textField{

        [_textFieldLocation resignFirstResponder]; //adding this line

        FilterLocationViewController *destViewController = (FilterLocationViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"FilterLocationViewController"];

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

}

(adding the line [textField resignFirstResponder];) the problem went away.

Basically the lesson is that you shouldn't modify the navigationController stack if the keyboard is out.

查看更多
干净又极端
4楼-- · 2019-01-08 06:14

This was happening for me because of my UIControlEvents

    [button addTarget:self action:@selector(callSecondView) forControlEvents:UIControlEventAllTouchEvents];

I had to change the UIControlEventAllTouchEvents to UIControlEventTouchUpInside or however you want your button to work if you had the issue because of a UIButton call.

查看更多
放我归山
5楼-- · 2019-01-08 06:15

Calling pushViewController before viewDidAppear is unsafe.

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-08 06:15

I know that this was answered, but it could help others.

I had the same problem, but it was caused because I was using a bad event for an info button. I was using "UIControlEventAllTouchEvents" and this generated two push of the same view into the navigation controller. The correct event was "UIControlEventTouchUpInside". I'm new to iOS.

查看更多
Rolldiameter
7楼-- · 2019-01-08 06:16

In my case I was both setting the push segue from the storyboard and programatically. Hopefully that'll help anyone

查看更多
登录 后发表回答