I want to show a warning message and I am using iOS SDK 8.1 with Xcode 6.1. I know that UIAlertView is deprecated; however, my application should also support iOS 7, and I should use UIAlertView if the application is running on an iOS 7 device. This warning window has a text box and two buttons, where one of them is the default cancel button. The other button should be disabled if the text box is empty.
Here is my code:
class MyViewController : UIViewController, UIAlertViewDelegate { var addRecipientAlertView:UIAlertView? // Irrelevant code here func performSomething(someValue:String) { addRecipientAlertView = UIAlertView(title: "Title", message: "Enter full name of user, email of user or a free-form text", delegate: self, cancelButtonTitle: "Cancel", otherButtonTitles: "Add Recipient") addRecipientAlertView!.alertViewStyle = UIAlertViewStyle.PlainTextInput addRecipientAlertView!.accessibilityValue = someValue // Text Field Settings let textField:UITextField = addRecipientAlertView!.textFieldAtIndex(0)! textField.placeholder = "Full Name, Email or Any Text" textField.keyboardType = UIKeyboardType.EmailAddress textField.clearButtonMode = UITextFieldViewMode.Always addRecipientAlertView!.show() } } func alertViewShouldEnableFirstOtherButton(alertView: UIAlertView) -> Bool { return false }
The problem is this: no matter what I tried, the first other button was not disabled anyway. Finally, I refused to check the text of the text field, and I applied the alertViewShouldEnableFirstOtherButton delegate method so that it always returned false. However, the result has not changed, and both buttons (named "Cancel" and "Add Recipient" in this example) are still enabled. What am I missing?
source share