title: iOS navigation issue: after pushing a ViewController, it results in a navigation bar showing the navigation items of the previous ViewController
body: <p>This situation happens very rarely and I don't know how to reproduce it, but it does happen sometimes and I would like to fix it.</p>
  
  <p>In <code>ViewController A</code>, if I push <code>ViewController B</code>in, sometimes(not always) when <code>ViewController B</code> did appear, the navigation bar is showing the navigation bar items of <code>ViewController A</code>, not those of <code>ViewController B</code>. If I click on the back button, I cannot go back to <code>ViewController A</code>, getting stuck in <code>ViewController B</code>.</p>
  
  <p>A <code>UIBarButtonItem</code> is added to the navigation items of <code>ViewController A</code>, and the navigation items of <code>ViewController A</code> will be updated in response to some events. Is it the reason that causes this issue?</p>
  
  <p><strong>Codes for pushing <code>ViewController B</code></strong></p>
  
  <pre><code>ViewControllerB* viewControllerB = [ViewControllerB new];
  [self.navigationController pushViewController:viewControllerB animated:YES];
  </code></pre>
  
  <p><strong>Codes for updating the navigation items in <code>ViewController A</code></strong></p>
  
  <pre><code>- (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];
              });
          }
      }
  }
  </code></pre>
  
  <p>/**
   * Show the update button on the right of navigation bar
   */</p>
  
  <pre><code>-(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]];}
  </code></pre>
  
  <p>/**
   * Start refresh animation on the update button
   */</p>
  
  <pre><code>-(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 &lt; updateButtonView.center.x){
                      updateButtonView = subViewInNavigationBar;
                  }
  
          }
  
          }
  
      }
  
      for (UIView *subViewsInButton in updateButtonView.subviews){
  
          if ([subViewsInButton isKindOfClass:[UIImageView class]] == YES &amp;&amp;
              subViewsInButton.frame.origin.x != 0.0f &amp;&amp;
              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;
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>Anyone has got a clue? Thank you.</p>