title: How to chain view controller navigations (NSNotification not being received)
body: <p>I have a custom in app notification appear at the top of any view controller on the screen when certain things happen.</p>
  
  <p>Tapping on it triggers a notification: </p>
  
  <p><code>[[NSNotificationCenter defaultCenter] postNotificationName:@"DidTapOnNotification" object:nil];</code></p>
  
  <p>The observer for that specific notification is the root navigation controller for my application, which I subclassed. I addObserver in <code>viewDidLoad</code>. This notification is always received, and the code I run in response is: </p>
  
  <pre><code>[CATransaction begin];
  [CATransaction setCompletionBlock:^{ // this is called when the popToRootViewController animation completes
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
          [[NSNotificationCenter defaultCenter] postNotificationName:@"NavigateToController" object:nil userInfo:notification.userInfo];
      });
  }];
  
  [self popToRootViewControllerAnimated:YES];
  
  [CATransaction commit];
  </code></pre>
  
  <p>I added a delay (dispatch_after) arbitrarily to see whether I just had to give my root view controller time to appear (i confirmed that it appeared before the 2 seconds are up).</p>
  
  <p>Now, in my root view controller I again, add it as an observer for the <code>NavigateToGroup</code> notification. I.e. I call <code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openController:) name:@"NavigateToController" object:nil];</code> in <code>viewDidLoad</code>.</p>
  
  <p>The problem is that the selector (i.e. the <code>openController:</code> method) is not always called. The only time it's called is when I'm already on that controller (the root controller) when I tap on the in app notification, then it works as expected. If I have other controllers on the navigation stack, tapping will popToRoot as expected, but then the method <code>openController:</code> will never get called even though I'm sure the notification gets posted (and i'm sure the view is appeared when it does).</p>
  
  <p>Does anyone know what's going on here?
  Or conversely, can anyone recommend a better way of handling this?</p>