简体   繁体   English

为文本字段创建观察者以启用/禁用按钮时发生错误(Swift 3,Xcode 8.x)

[英]Error when creating observer for textfield to enable/disable button (Swift 3, Xcode 8.x)

I am trying to create an observer for when the specified text field ends editing in order to disable/enable a button that forwards to a new segue. 我正在尝试为指定的文本字段何时结束编辑创建观察者,以禁用/启用转发到新序列的按钮。

In the end, I want to have a button that is only enabled when the the textfield is full and finished editing, which will allow it to move on to the next VC. 最后,我希望有一个仅在文本字段已满并完成编辑时才启用的按钮,这将使其继续前进到下一个VC。

The error that is showing is: 显示的错误是:

 Cannot call value of non-function type '((UITextFieldDelegate) -> (UITextField) -> Bool)?'

Here's my source code: 这是我的源代码:

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)

}

}

Thank you for any help, I truly appreciate it. 谢谢您的帮助,我非常感谢。

您应该删除addTarget因为它会与UITextFieldDelegatetextFieldShouldEndEditing发生冲突,并应直接使用它来知道文本字段何时完成编辑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM