title: What is wrong with the segue and NavigationController navigation
body: <p>This is a continuation/alternative of this thread: <a href="https://stackoverflow.com/questions/19365260/self-navigationcontroller-poptorootviewcontrolleranimatedyes-do-not-pop-back-to">popToRootViewControllerAnimated problem</a> to sort out what is the problem/mistake in a more structured and easier to understand way. </p>
  
  <p>When pressing the back button in VC3 i want to go back to VC1.</p>
  
  <p>I have the following setup:</p>
  
  <p><img src="https://i.stack.imgur.com/JMIid.png" alt="enter image description here"></p>
  
  <p>The following code:</p>
  
  <p>VC1:</p>
  
  <pre><code>@implementation ViewController
  - (IBAction)myButton1:(id)sender {
  
  //Call InformationViewController for Quick Game
  [self performSegueWithIdentifier:@"toVC2" sender:self];
  
  
  }
  
  - (void)viewDidLoad
  {
  [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  }
  
  - (void)didReceiveMemoryWarning
  {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  }
  
  @end
  </code></pre>
  
  <p>VC2:</p>
  
  <pre><code>@implementation nrTwoViewController
  - (IBAction)myButton2:(id)sender {
  //Call InformationViewController for Quick Game
  [self performSegueWithIdentifier:@"toVC3" sender:self];
  
  }
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
      // Custom initialization
  }
  return self;
  }
  
  - (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  }
  
  - (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  }
  
  @end
  </code></pre>
  
  <p>VC3:</p>
  
  <pre><code>@implementation nrThreeViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
      // Custom initialization
  }
  return self;
  }
  
  - (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  
  
  }
  
  - (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  }
  
  - (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  [self.navigationController popToRootViewControllerAnimated:YES];
  }
  
  
  @end
  </code></pre>
  
  <p>I only pop to VC2, not the root (VC1), and get the following message when pressing back button on VC3:</p>
  
  <pre><code>2013-10-15 08:36:08.479 segueTest[44153:a0b] nested pop animation can result in corrupted navigation bar
  2013-10-15 08:36:08.831 segueTest[44153:a0b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
  </code></pre>
  
  <p>I also tried, as suggested, adding the UINavigationBarDelegate:</p>
  
  <pre><code>@interface nrThreeViewController : UIViewController &lt;UINavigationBarDelegate&gt;
  </code></pre>
  
  <p>...and:</p>
  
  <pre><code>- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
  [self.navigationController popToRootViewControllerAnimated:YES];
  return NO;
  }
  </code></pre>
  
  <p>The result: </p>
  
  <blockquote>
    <p>pop'ed from VC3 to VC2 only with no messages in the console.</p>
  </blockquote>