2014-11-17 215 views
5

我想显示一条警报消息,我正在使用iOS SDK 8.1和XCode 6.1。我知道UIAlertView已被弃用;然而,我的应用程序也必须支持iOS 7,如果应用程序在iOS 7设备上运行,我必须使用UIAlertView。此警报视图具有文本字段和两个按钮,其中一个是默认取消按钮。只要文本字段为空,则应该禁用另一个按钮。alertViewShouldEnableFirstOtherButton委托方法没有被调用

这里是我的代码:

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 
} 

的问题是;无论我尝试过,第一个其他按钮是不是禁用无论如何。最后,我放弃了试图检查我的文本字段的文本,并且我实现了alertViewShouldEnableFirstOtherButton委托方法,以便它总是返回false。但是,结果并没有改变,并且两个按钮(在本例中均被命名为“取消”和“添加收件人”)仍处于启用状态。我错过了什么?

回答

1

我有同样的问题,我想这是在SDK中的错误。我设法提供的唯一工作解决方案是实现一个Objective-C类,它显示了警报并作为它的代表。