2

這種情況很少發生,我不知道如何重現它,但它有時會發生,我會喜歡解決它。iOS導航問題:在推送ViewController後,導致顯示前一個ViewController的導航條的導航欄

ViewController A,如果我在,有時候(不總是)在ViewController B沒有出現,導航欄顯示的ViewController A導航欄項目,而不是那些ViewController BViewController B。如果我點擊後退按鈕,我不能回到ViewController A,陷入ViewController B

A UIBarButtonItem已添加到導航條目ViewController A,導航條目ViewController A將根據某些事件進行更新。這是導致這個問題的原因嗎?

代碼爲ViewController A

- (void)viewDidAppear:(BOOL)animated{ 

    [super viewDidAppear:animated]; 

    if(NumberOfCalendarOperations == 0){ 
     [self showNavigatorBarButtons]; 
    } 
    else{ 
     [self startRefreshAnimationOnUpdateButton]; 
    } 
} 



//This method is triggered through notification when the number of operations in calendarOperationQueue is changed 

-(void)calendarOperationQueueStateDidChange:(NSNotification*)notification{ 
    if(NumberOfCalendarOperations == 0){ 

     if (self.isShowActivityIndicator) { 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       [self showNavigatorBarButtons]; 
      }); 
     } 
    } 
    else{ 
     if (!self.isShowActivityIndicator) { 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       [self startRefreshAnimationOnUpdateButton]; 
      }); 
     } 
    } 
} 

/** 推ViewController B

ViewControllerB* viewControllerB = [ViewControllerB new]; 
[self.navigationController pushViewController:viewControllerB animated:YES]; 

代碼用於更新導航項*顯示在導航欄 右側的更新按鈕*/

-(void)showNavigatorBarButtons{ 
    self.isShowActivityIndicator = NO; 
    UIBarButtonItem *updateButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sync.png"] style:UIBarButtonItemStylePlain target:self action:@selector(updateButtonDidPress:)]; 
    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:updateButton, nil]];} 

/** * 上開始更新按鈕 */

-(void)startRefreshAnimationOnUpdateButton{ 

    if (self.navigationController.topViewController != self) { 
     return; 
    } 
    self.isShowActivityIndicator = YES; 

    UIView* updateButtonView = nil; 

    for (UIView *subViewInNavigationBar in self.navigationController.navigationBar.subviews){ 

    NSString *subViewClassAsString = NSStringFromClass([subViewInNavigationBar class]); 

     if ([subViewClassAsString compare:@"UINavigationButton" /* TODO: be careful with this */ 
           options:NSCaseInsensitiveSearch] == NSOrderedSame){ 

     if ([subViewInNavigationBar isKindOfClass:[UIView class]] == YES){ 

       if(updateButtonView == nil){ 
        updateButtonView = subViewInNavigationBar; 
       } 
       else if(subViewInNavigationBar.center.x < updateButtonView.center.x){ 
        updateButtonView = subViewInNavigationBar; 
       } 

     } 

     } 

    } 

    for (UIView *subViewsInButton in updateButtonView.subviews){ 

     if ([subViewsInButton isKindOfClass:[UIImageView class]] == YES && 
      subViewsInButton.frame.origin.x != 0.0f && 
      subViewsInButton.frame.origin.y != 0.0f){ 

      [subViewsInButton removeFromSuperview]; 


      CGRect activityIndicatorFrame = self.updateButtonActivityIndicator.frame; 
      activityIndicatorFrame.origin.x = (CGRectGetWidth(updateButtonView.frame)/2.0f) - (CGRectGetWidth(activityIndicatorFrame)/2.0f); 
      activityIndicatorFrame.origin.y = (CGRectGetHeight(updateButtonView.frame)/2.0f) - (CGRectGetHeight(activityIndicatorFrame)/2.0f); 
      self.updateButtonActivityIndicator.frame = activityIndicatorFrame; 

      [self.updateButtonActivityIndicator startAnimating]; 

      [updateButtonView addSubview:self.updateButtonActivityIndicator]; 

      return; 

     } 

    } 

} 

任何人都得到了一個線索刷新動畫?謝謝。

+0

你是怎麼在ViewControllerA中添加欄按鈕的? – channi

+0

任何代碼顯示? –

+0

是的,一個UIBarButtonItem被添加到A的導航項中,並且A的導航項將被更新以響應一些事件。 – Jibeex

回答

0

最後我找到了這個問題的原因。這是我試圖隱藏viewWillDisappear中的導航欄。現在iOS允許我通過從屏幕左邊緣進行平移來回到前一個視圖。但是,從左邊緣平移時,如果我取消此操作並平移回左邊緣,導航欄將進入此奇怪狀態。