I would like to prevent the UIAlertController
from dismissing.
I have a UIAlertAction
that simply appends a string into the UIAlertTextField, however, once tapped it dismisses the view controller [undesired]. I've tried adding an NSNotification with undesired results.
UIAlertAction *pasteMessage = [UIAlertAction actionWithTitle:@"Paste Message" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UITextField *textField = alertC.textFields.firstObject;
textField.text = [textField.text stringByAppendingString:[NSString stringWithFormat:@"%@", copiedString]];
}];
I've also tried setting no to pasteMessage by:
[alertC canPerformAction:@selector(dismissViewControllerAnimated:completion:) withSender:pasteMessage];
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
UIAlertAction *paste = alertController.actions.firstObject;
if (paste) {
flag = NO;
} else {
flag = YES;
}
}
Edit, i'm not looking to prevent the tapping of UIAlertAction
i'm looking to prevent the UIAlertController
from dismissing when tapping on said action. The action can be enabled/disabled whatever, but my goal is to simply paste the copied message into the UITextField
by pressing an action (hence the reason I don't want it to be dismissed)
I also realize setting the BOOL to dismissViewControllerAnimated:
simply sets it to not animate the view controllers dismissal, I don't want it to imply it was for stopping the actual dismissal process. Simply offering the things I've tried in relation to my goal. I've also tried presenting a new UIAlertController
when selecting pasteMessage auto-populating the new UIAlertControllers
textField with the copied message, it works, but I feel like it's too hacky for what could be done.
= (tf.text != "")
that just disables the button from allowing the view from being dismissed eventually – AuroraauroralUIAlertAction
will dismiss your alert. If you want some other behavior, try creating your own custom view. – Creditor