Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alertViewShouldEnableFirstOtherButton delegate method does not being called

I want do display an alert message and I am using iOS SDK 8.1 with XCode 6.1. I know that UIAlertView is deprecated; however, my app has to support also iOS 7 and I have to use UIAlertView if the app is running on an iOS 7 device. This alert view has a text field and two buttons where one of them is default cancel button. The other button should be disabled as long as text field 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; whatever I have tried, the first other button was not disabled anyway. Finally I gave up trying to check the text of my text field and I have implemented the alertViewShouldEnableFirstOtherButton delegate method such that it always return false. However, the result has not changed and both of the buttons (named "Cancel" and "Add Recipient" in this example) are still enabled. What am I missing?

like image 248
natuslaedo Avatar asked Nov 09 '22 23:11

natuslaedo


1 Answers

I had the same problem and I guess it's a bug in the SDK. The only working solution that I managed to come up with with was to implement an Objective-C class that showed the alert and served as its delegate.

like image 182
alchemiss Avatar answered Dec 16 '22 00:12

alchemiss