I'm updating an Objective-C application in iOS and since UIAlertView is deprecated I'm using UIAlertController with UIAlertAction for the OK and Cancel buttons. So I have the following function for the back button but I don't know how to handle the OK and Cancel buttons since the OK should let you go back to the previous screen and the Cancel should let you stay in the same screen. The following is my code so far.
- (void)backAction:(id)sender
{
//do your saving and such here
if ([doneBtn isEnabled])
{
//CHANGE 2018
UIAlertController *alert = [UIAlertController alertControllerWithTitle: @"Alert" message:@"Signature will be lost. Do you want to continue?." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle: @"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
//should go to the previous scree.
//[alert dismissViewControllerAnimated:TRUE completion:nil]; //I'm not sure if this only hides the alert or hides the entire screen
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle: @"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
//should stay in the same screen
[alert dismissViewControllerAnimated:TRUE completion:nil]; //the same doubt
}];
[alert addAction: ok];
[alert addAction: cancel];
[self presentViewController:alert animated:YES completion:nil];
//UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Signature will be lost. Do you want to continue?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
//[alert show];
}