Miguel Miguel -4 years ago 119
Objective-C Question

unwind segue programmatically

I cant seem to be able to do this correctly so I'll try to explain the best I can. I have view controller 1 and then within view controller one I then create another view to basically show as thought is hovering over the current view(lets call it 2). That view now has a button and i need to go back to view 0 which is where it all started. so I created a segue and then i try to perform the segue but in not getting anywhere.
so here is how i attempted to accomplish this .
In view 1 i have this

// this is in the nearmeView controller
-(void)BackToStart{
[self performSegueWithIdentifier:@"unwind" sender:self];
//dismissViewControllerAnimated:completion:

}


in the popped up view i have this.

NearMeViewController * goBackToBeggining = [[NearMeViewController alloc]init];
[goBackToBeggining BackToStart];


however i get an error that says this?

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<NearMeViewController: 0x19af9600>) has no segue with identifier 'unwind''


now i know is must be me not instatiating the view correctly how should i do this? what I'm i missing?
I read this post but it didn't help much any ideas?
Unwind segue not being triggered

Answer Source

Unwind segues are tricky. For this case, however, you don't even need one; just have your BackToStart call [self.navigationController popViewControllerAnimated:YES]. However, if you're using storyboards and need to use an unwind segue, you have to add an IBAction method to the target view controller, and it has to take a UIStoryboardSegue argument:

- (IBAction)comeToPapa:(UIStoryboardSegue *)segue {
    // ... whatever
}

Then, in your child view controller's storyboard scene, ctrl+drag from whatever triggers the unwind and drag it up to the child view controller's green Exit icon in the scene header. This will pop up a list of available unwind segues; select the one you just created in the parent view controller.

Here's what Apple says about it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download