I have watched the apple demo video on storyboard implementation with the unwind segues section and seen the demo using custom buttons on the main view. That works fine.
In the end I didn't need to unwind the segue since I could still get a reference to the parent controller methods by following the navigation controller.
I was able to get a reference by doing the following in the - (void)viewWillDisappear:(BOOL)animated
method of the child controller
NSInteger currentVCIndex = [self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];
FirstViewController *parent = (FirstViewController *)[self.navigationController.viewControllers objectAtIndex:currentVCIndex];
parent.barcodeType = indexPath.row;
which passed the settings variable back to the original controller perfectly.
I also added an import reference to the parent controller at the top of the childcontroller
An alternative you might have not considered is to make the parent a delegate of the child and use delegate methods in the child to update the parent.
That way you would bypass the need to add to the navigation unwind, because the parent is already up to date the moment you hit back.
I'd like to add a Swift solution that follows @Chuck H suggestion above:
let rootVC = self.navigationController!.topViewController
if rootVC.isKindOfClass(TheNameOfYourViewController) {
performSegueWithIdentifier("yourNamedSegueIdentifier", sender: self)
}
@Alan is on the right track. Just add a test to prevent the segue from firing when not going back to the first view controller. Something like this in viewWillDisappear will actually allow you to perform the unwind segue for a back button. You will need to create a manual unwind segue by dragging from the class down to the exit icon. Be sure to name it after you create it.
UIViewController *vc = self.navigationController.topViewController;
if ([FirstViewController class] == [vc class])
{
[self performSegueWithIdentifier:@"unwindSegue" sender:self];
}