UIAlertControllerにそのアクションを追加しながらあなたは以下のコード
alertAction = UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil)
alertAction.isEnabled = false
let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addTextField { (textField) in
textField.delegate = self
}
alert.addAction(alertAction)
self.present(alert, animated: true, completion: nil)
中などの偽のプロパティ
isEnabled
を設定する必要が今この
var alertAction = UIAlertAction()
のようなグローバル変数としてあなたUIAlertActionを作成する必要があります
代理メソッドのshouldChangeCharacterの後に、値がUITextFieldに入力されている場合、このようなボタンを有効にする必要があります。
ここ
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let userEnteredString = textField.text
let newString = (userEnteredString! as NSString).replacingCharacters(in: range, with: string) as NSString
if newString != ""{
alertAction.isEnabled = true
} else {
alertAction.isEnabled = false
}
return true
}
は、あなたが変更をリッスンするUITextFieldDelegateを使用したいと思う
実施例です。 – sdasdadas
'UIAlertView'はしばらく前に廃止されました。あなたは 'UIAlertController'を使うべきです。 – rmaddy