【问题标题】:nested push animation can result in corrupted navigation bar error嵌套推送动画可能导致导航栏损坏错误
【发布时间】:2012-07-06 06:08:41
【问题描述】:

据我所知,我不相信我做错了什么,但是我得到了:

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.

这是我的代码

- (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]; 

}

我用谷歌搜索了它,但是大多数地方都在谈论放置动画:不,但是我在下一个屏幕上看不到地图。

【问题讨论】:

标签: ios uinavigationcontroller pushviewcontroller


【解决方案1】:

每次 CLLocationManager 通知来自同一控制器的位置更改时,您都会推送一个新控制器。这会导致嵌套导航。尝试在第一次通知您时在该控制器中保存对 LocationMapViewController 的引用,然后检查它以通知它:

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)];
}

另一种选择是在 LocationMapViewController 中创建 CLLocationManager...

【讨论】:

    【解决方案2】:

    我发现另一种解决方案可以将我的所有代码转换为情节提要,并且walla,它又可以工作了。甜的。它并不像看起来那么难,干杯,tronnick

    【讨论】:

      【解决方案3】:

      确保您没有同时将两个或多个UIViewControllers 推入导航堆栈。

      【讨论】:

      • 欢迎来到stackoverflow。如果您通过参考和/或一些解释来改进您的答案,那就太好了。
      【解决方案4】:

      我不能 100% 确定这是否解决了您的具体问题,但是当我试图在视图控制器出现之前弹出一个视图控制器时,我收到了 nested pop animation can result in corrupted navigation bar 消息。覆盖viewDidAppear 以在您的 UIViewController 子类中设置一个标志,指示视图已出现(请记住也调用[super viewDidAppear])。在弹出控制器之前测试该标志。如果视图尚未出现,您可能需要设置 another 标志,表明您需要在视图控制器出现后立即从viewDidAppear 中弹出它。像这样:

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

      ...在@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;
          }
      }
      

      重复的popViewControllerAnimated 调用有点难看,但我可以让它在我目前疲倦的状态下工作的唯一方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-19
        相关资源
        最近更新 更多