0

I have a firstViewController embedded in a firstNavigationController that has a modal segue to a new secondViewController embedded in another secondNavigationController. This new controller performs an unwind segue back to the firstViewController

secondViewController:

- (void) cancelAction{
     [self performSegueWithIdentifier:@"backHoney" sender:self];
}

firstViewController:

- (IBAction)backToHoney:(UIStoryboardSegue *)sender{
}

This works but there is a case when another viewC embedded in a Nav has a modal segue to the firstViewController. When the user goes from this viewC to the firstViewController then to the secondViewController and tries to unwind back to the first, it unwinds all the way back to viewC instead of the first.

Peter
  • 1,053
  • 13
  • 29

1 Answers1

0

you should use popToviewController instead of unwing segue. you can go to any viewController of navigation stack by this.

for example,

NSArray *viewArr = [self.navigationController viewControllers];   //returs viewcontroller array
[self.navigationController popToViewController:[viewArr objectAtIndex:0] animated:YES];
//you can pass different index to go to differen VC

You can refer my this answer for more detail.

hope this will help :)

Community
  • 1
  • 1
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • I need to unwind from `secondNavController` to `firstNavController`. Also passing data. Isn't this just for navigating about all viewControllers within the same NavController? @Lion – Peter Apr 27 '16 at 12:39
  • you can use delegate and protocol for pass the data. there is nothing mandatory to use unwind segue. – Ketan Parmar Apr 27 '16 at 12:43