Unwind Segue Programmatically - New twist

cocoa-touch, ios, segue

Solution

`[self performSegueWithIdentifier:@"UnwindSegueIdentifier" sender:self]` should work just fine. Unwind segues do not create new instances of their destinations, no matter how they're performed. They are unique in that it's the only segue that does not create a new instance of the destination.

Problem

Context: I have two VC, A and B. VC A contains several buttons and several labels. When pressing the button in VC A a segue will display VC B/C/ and so forth. Now, when finished with VC A/B/C so forth, the segue is being unwind so that VC A appears. For most of the VC B/C/D so forth, I am using the unwind method which I trigger through a button in that VC (ctrl + drag to "exit" icon). This works perfect, because upon returning to VC A, the following action is being called automatically: ``` - (IBAction)returned:(UIStoryboardSegue *)segue { // Here I do some stuff } ``` Problem: Now, in one of the secondary VCs (e.g. D), things are a bit special. In this VC I generate some hundred buttons through a loop programmatically, then detect which button is being pressed and finally unwind back to VC A (without a specific button; any of the buttons will trigger the unwind). I know I can do this eg by using this ``` [self dismissViewControllerAnimated: YES completion: nil] ``` but this does not trigger the above action when returning to VC A, or by using this ``` [self performSegueWithIdentifier:@"UnwindSegueIdentifier" sender:self] ``` but this will generate a new instance of VC A, which I do not want (because labels in the instance of VC A already contains some information). So, what I want is to be able to return to the same instance of VC A which generated the VC D, and also trigger the "returned" action listed above. Thus, I want to achieve the same effect as when using a button connected to the "exit" icon, but I want to do this programmatically "inside the code" when one the many buttons in VC D is pressed. Any thoughts?

Original source

Related problems