View of the UIAlertController from a moderated controller that deviates

Prior to iOS 8, a UIAiewertView could be displayed from a modally represented UIViewController at the same time that the UIViewController was fired. I found this to be especially useful when the user needs to be warned about some changes that occurred when they clicked the "Save" button on the fashionably presented controller. Starting with iOS 8, in the case when the UIAlertController is displayed from a fashionably presented view controller during its rejection, the UIAlertController is also rejected. UIAlertController is fired before the user can read or reject it. I know that I can have a delegate for a modally represented controller that displays a warning view after the controller is rejected, but in this case a ton of extra work is created,since this controller is used in many places, and the UIAlertController must be presented with certain conditions, requiring that the parameters be passed back to the controller delegate in each case. Is there a way to display the UIAlertController from a modally represented controller (or at least from the code in the controller) while turning off the controller and staying in the UIAlertController until it is rejected?until it is rejected?until it is rejected?

+4
source share
1 answer

You can handle this in the reject block of the rejectViewControllerAnimated method of your modal controller classes. Imagine a UIAlertController in a root controller that should be processed in any class.

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationItem.rightBarButtonItem setAction:@selector(dismissView)];
[self.navigationItem.rightBarButtonItem setTarget:self];
}
- (void)dismissView {
[self dismissViewControllerAnimated:YES completion:^{
    [self showAlert];
}];
}

- (void)showAlert {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert" message:@"This is Alert" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okButton = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    [alertController dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    [alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:okButton];
[alertController addAction:cancelButton];
UIViewController *rootViewController=[UIApplication sharedApplication].delegate.window.rootViewController;
[rootViewController presentViewController:alertController animated:YES completion:nil];
}
+2
source

All Articles