Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UIAlertView call `alertViewShouldEnableFirstOtherButton:` after making changes?

I have a UIAlertView with a UITextField. I have connected the UIAlertView delegate and I return YES or NO in alertViewShouldEnableFirstOtherButton: depending on the text in the UITextField.

I need to change the text of the textField programmatically. This works as expected.

Unfortunately I don't know how to make the UIAlertView call the alertViewShouldEnableFirstOtherButton: delegate method so it enables or disables the other button after I changed the text of the textField.

I thought the UIAlertView registers as a target of UITextField, so I tried to send a UIControlEventValueChanged from the textField. Didn't work.


From the stack trace I figured out the delegate method is called from the private UIAlertView method _alertSheetTextFieldDidChange:.

So if I do [self.currentAlert performSelector:@selector(_alertSheetTextFieldDidChange:) withObject:textField]; after changing the text, the delegate method is called and the enable state of the button changes. But, since this is a private method, the app will probably be rejected. I don't want to risk that.


Is there a clean way to make the alert view call alertViewShouldEnableFirstOtherButton:?

like image 639
Matthias Bauch Avatar asked Apr 22 '13 12:04

Matthias Bauch


1 Answers

I was on the right track with sending a control event. I just choose the wrong event.

This will work:

[textField sendActionsForControlEvents:UIControlEventEditingChanged];
like image 120
Matthias Bauch Avatar answered Sep 28 '22 06:09

Matthias Bauch