0
指定されたテキストフィールドが編集を終了したときにオブザーバーを作成しようとしています。新しいセグエ。ボタンを有効/無効にするためのオブザーバーを作成するときにエラーが発生する(Swift 3、Xcode 8.x)
最後に、テキストフィールドが一杯になって編集が完了したときにのみ有効になるボタンがあり、次のVCに移動することができます。
見せているエラーは次のとおりです。
Cannot call value of non-function type '((UITextFieldDelegate) -> (UITextField) -> Bool)?'
ここに私のソースコードは次のとおりです。
import UIKit
class EmailViewController: UIViewController, UITextFieldDelegate {
// Back Button Two
@IBOutlet weak var backButtonTwo: UIButton!
// Email Header
@IBOutlet weak var emailSloganLabel: UILabel!
@IBOutlet weak var emailDescSloganLabel: UILabel!
// Email Form Entries
@IBOutlet weak var emailAddressMiniHeader: UILabel!
@IBOutlet weak var emailAddressTextField: UITextField!
@IBOutlet weak var emailAddressLineBreak: UILabel!
// Bottom Bar 'Next' Navigation
@IBOutlet weak var bottomNextButtonTwo: UIButton!
@IBOutlet weak var bottomNextLineBreakTwo: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
emailAddressTextField.delegate = self
emailAddressTextField.addTarget(self, action: #selector(UITextFieldDelegate.textFieldShouldEndEditing("textFieldDidChange:")), for: UIControlEvents.editingChanged)
}
internal func textFieldShouldEndEditing(_ emailAddressTextField: UITextField) -> Bool { if self.emailAddressTextField.text == "" {
self.bottomNextButtonTwo.isEnabled = false
} else {
self.bottomNextButtonTwo.isEnabled = true
}
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// Hide keyboard when user touches the outside keyboard
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
// Hides keyboard when user pressed the 'Return' Key
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
emailAddressTextField.resignFirstResponder()
return (true)
}
}
は、私は本当にそれを感謝し、任意の助けてくれてありがとう。それはと競合するので、
あなたは 'UITextFieldDelegate'から 'textFieldShouldEndEditing'を変更しようとしない理由がある場合に知ってそれを直接使用する必要がありますそれを指すようにターゲットを追加しますか?それをデフォルトのものに戻してください – Tj3n
このようにしますか? UIControlEvents.editingChanged) ' –
' addTarget 'を削除し、' func textFieldShouldEndEditing(textField:UITextField) - > Bool'を追加します。あなたが知りたいのであれば 'emailAddressTextField.addTarget(self、action:#selector(UITextFieldDelegate(textFieldDidChange :))テキストフィールドの編集が終わると – Tj3n