Reputation: 1375
I have a modally presented view controller which I want to unwind. I have it set up that if I press "cancel", it will execute an unwind segue. But, I want to make a confirmation button using UIAlertView. As in, "Are you sure you'd like to cancel?". How can I use the UIAlertView buttons to trigger an unwind segue?
Upvotes: 0
Views: 210
Reputation: 81
Declare a manual unwind segue from the storyboards by selecting the whole view controller and ctrl dragging the mouse to exit. Give that segue an identifier and fire the segue from delegate of the UIAlertView using performSegueWithIdentifier method
Upvotes: 0
Reputation: 150
In your .h file, declare UIAlertViewDelegate
. And then in your .m file, you can write code in cancel button action method:
- (IBAction)confirmationButtonPressed:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Are you sure you'd like to cancel?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
[alert show];
}
And then you can add UIAlertView Delegate method in your .m file:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Upvotes: 2