创建textfield的观察者以启用/禁用按钮时出错(Swift 3,Xcode 8.x)

时间:2016-11-22 00:35:48

标签: ios swift xcode

我正在尝试为指定的文本字段结束编辑时创建一个观察者,以便禁用/启用转发到新segue的按钮。

最后,我想要一个仅在文本字段已满且已完成编辑时启用的按钮,这将允许它移动到下一个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)

}

}

感谢您的帮助,我真的很感激。

1 个答案:

答案 0 :(得分:1)

您应该删除addTarget,因为它会与UITextFieldDelegate的{​​{1}}冲突,并且应该直接使用它来了解文本字段何时完成编辑

相关问题