I have a 3 viewcontroller navigation where A presents modal controller B, which presents modal controller C all via segues. C has an unwind segue back to B. It also has an unwind back to A. When I perform action for C to unwind to B, it unwinds but then pops B and goes back to A. This is not what I want, I want it in this case to stay on B. Below are the segues VC C uses.
unwindCancel is for when user clicks on a collectionViewCell and goes back to VC B. prepareForUnwind is just a standard "cancel" button to VC A.
Below is code for didSelectItem to call the unwind in VC C. Below that is prepareForSegue in VC C.
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[self performSegueWithIdentifier:@"unwindCancel" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"unwindCancel"]) {
GalleryDetailViewController *detailVC = segue.destinationViewController;
detailVC.colletionCount = self.indexPathToPass;
}
}
VC B unwind in .m file
-(IBAction)unwindCancel:(UIStoryboardSegue *)segue{
[self.collectionView scrollToItemAtIndexPath:self.colletionCount atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
}
VC A unwind in .m file
-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
}
When going from C to B, don't use an unwind segue just have C call dismissViewController. If you're committed to using unwind segues, look here specifically section entitle How an Unwind Segue Determines its Destination View Controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With