alertViewShouldEnableFirstOtherButton委托方法未被调用

nat*_*edo 5 iphone uialertview ios swift

我想显示一条警告消息,我正在使用带有XCode 6.1的iOS SDK 8.1.我知道UIAlertView已被弃用; 但是,我的应用程序还必须支持iOS 7,如果应用程序在iOS 7设备上运行,我必须使用UIAlertView.此警报视图有一个文本字段和两个按钮,其中一个是默认取消按钮.只要文本字段为空,就应禁用其他按钮.

这是我的代码:

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
}
Run Code Online (Sandbox Code Playgroud)

问题是; 无论我尝试过什么,第一个其他按钮都没有被禁用.最后,我放弃了尝试检查文本字段的文本,并实现了alertViewShouldEnableFirstOtherButton委托方法,使其始终返回false.但是,结果没有改变,并且仍然启用了两个按钮(在此示例中名为"取消"和"添加收件人").我错过了什么?

alc*_*iss 1

我也遇到了同样的问题,我猜这是 SDK 中的一个错误。我想出的唯一可行的解​​决方案是实现一个 Objective-C 类来显示警报并充当其委托。