Reputation: 744
I'm trying to pass data back to my source view controller by performing an unwind segue. I found an answer for this here: Unwind segue with Navigation back button
I followed the instructions in the first answer, but the segue is never triggered.
In the source view controller's .h:
- (IBAction)returnJ:(UIStoryboardSegue *)segue;
Here's my source view controller .m:
- (IBAction)returnJ:(UIStoryboardSegue *)segue
{
NSLog(@"Returned");
if ([[segue identifier] isEqualToString:@"return Jobs"]) {
NSLog(@"Retuned");
resSolarViewController *returnController = [segue sourceViewController];
if (returnController.jobsList) {
self.jobs = returnController.jobsList;
[[self tableView] reloadData];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
}
I'm pretty sure I have everything hooked up correctly in IB, but the neither of the NSLogs are never shown in the console.
What am I doing wrong?
Thanks.
Upvotes: 1
Views: 5480
Reputation: 8266
@JosephGagliardo is on the right track. However, you must 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 an unwind segue for a back button. You don't need an action segue from a dummy (off screen) button. Just 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];
}
Upvotes: 1
Reputation: 71
I created a regular UIButton and wired that to the exit segue I wanted. I then made the button invisible and moved it's X,Y co-ordinate off the screen. Find the segue in the dock and on the attribute inspector for it, give it a name. Then in the viewWillDisappear I programmatically invoked the segue by name:
[self performSegueWithIdentifier:@"unwindFromSettings" sender:self];
I do this for both normal and unwind segues. Creating a hidden button as the GUI placeholder for a segue that I invoke programatically.
Upvotes: 0
Reputation: 458
If only pass data back to your source view controller, you can use delegate to do it. How to pass prepareForSegue: an object
Upvotes: 1