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?
0
votes
2 Answers
2
votes
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];
}
}