1

To the best of my knowedge I do not believe I am doing anything wrong however I am getting:

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 my code

- (IBAction) btnGetCurrentLocation{
    [SVProgressHUD showWithStatus:@"Getting current location..."];
    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];
    [SVProgressHUD dismiss];
}

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
           fromLocation:(CLLocation *)oldLocation {

    [locationManager stopUpdatingLocation];
    CLLocationCoordinate2D coordinate = newLocation.coordinate;

    LocationMapViewController *locationMapViewController = [[LocationMapViewController alloc] initWithNibName:@"LocationMapViewController_iPhone" bundle:nil];
    locationMapViewController.title=@"Your Title";
    locationMapViewController.centerOfMap = &(coordinate);
    [self.navigationController pushViewController:locationMapViewController animated:YES]; 

}

I googled it however most places talk about putting animation:NO however then I do not see the map on next screen.

Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169
  • Check this http://stackoverflow.com/questions/5525519/iphone-uinavigation-issue-nested-push-animation-can-result-in-corrupted-naviga – Rui Peres Jul 06 '12 at 06:17

4 Answers4

4

You are pushing a new controller every time that CLLocationManager notify a change of location from the same controller. That results in a nested navigation. Trying to hold a reference to LocationMapViewController in that controller at first time that you are being notified, and later check it to notify it:

if (self.locationController == null){
     LocationMapViewController *locationMapViewController = [[LocationMapViewController alloc] initWithNibName:@"LocationMapViewController_iPhone" bundle:nil];
    locationMapViewController.title=@"Your Title";
    locationMapViewController.centerOfMap = &(coordinate);
    [self.navigationController pushViewController:locationMapViewController animated:YES]; 
}else{
    [self.locationController locationDidChangeTo: &(coordinate)];
}

Another alternative is creating the CLLocationManager in the LocationMapViewController...

Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75
2

Another solution I found I could convert all my code into storyboard, and walla, it works again. sweet. its not as hard as it looks, cheers, tronnick

tronnick
  • 21
  • 1
1

Make sure you haven't pushed into navigation stack two or more UIViewControllers at the same time.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
HotJard
  • 4,598
  • 2
  • 36
  • 36
  • Welcome to stackoverflow. It would be nice if you improved your answer by a reference and/or a bit of explanation. – Shahbaz Jul 16 '12 at 12:20
0

I'm not 100% sure if this addresses your specific problem, but I got the nested pop animation can result in corrupted navigation bar message when I was trying to pop a view controller before it had appeared. Override viewDidAppear to set a flag in your UIViewController subclass indicating that the view has appeared (remember to call [super viewDidAppear] as well). Test that flag before you pop the controller. If the view hasn't appeared yet, you may want to set another flag indicating that you need to immediately pop the view controller, from within viewDidAppear, as soon as it has appeared. Like so:

@interface MyViewController : UIViewController {
    bool didAppear, needToPop;
}

...and in the @implementation...

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    didAppear = YES;
    if (needToPop)
        [self.navigationController popViewControllerAnimated:YES];
}

- (void)myCrucialBackgroundTask {
    // this task was presumably initiated when view was created or loaded....
    ...
    if (myTaskFailed) {  // o noes!
        if (didAppear)
            [self.navigationController popViewControllerAnimated:YES];
        else
            needToPop = YES;
    }
}

The duplicated popViewControllerAnimated call is a bit ugly, but the only way I could get this to work in my currently-tired state.

Ian Holmes
  • 149
  • 1
  • 11