简体   繁体   English

未调用 iOS Swift 的 UITextField 选择器函数

[英]UITextField Selector Function Not Being Called iOS Swift

I created a textField configured simple, but my action function won't be called for some reason no idea why (ie my breakpoint won't even get hit)我创建了一个配置简单的 textField,但由于某种原因不会调用我的操作函数,不知道为什么(即我的断点甚至不会被击中)

TextField code:文本字段代码:

lazy var inputField: UITextField = {
   let textField = UITextField()
    textField.borderStyle = .none
    textField.font = UIFont.systemFont(ofSize: 16)
    
    let paddingView = UIView()
    paddingView.setDimensions(height: 50, width: 28)
    textField.leftView = paddingView
    textField.leftViewMode = .always
    
    textField.addTarget(self, action: #selector(handleUpdateUseerInfo), for: .editingDidEnd)
    
    return textField
}()

Action func code:动作功能代码:

@objc
func handleUpdateUseerInfo(sender: UITextField) {
    guard let valeu = sender.text else { return }
    delegate?.settingsCell(self, wantsToUpdateUserWith: valeu, for: viewModel.section)
}

The selector if probably in wrong format.选择器如果可能格式错误。 Try replacing this line:尝试替换此行:

textField.addTarget(self, action: #selector(handleUpdateUseerInfo), for: .editingDidEnd)

With this:有了这个:

textField.addTarget(self, action: #selector(handleUpdateUseerInfo(sender:)), for: .editingDidEnd)

It's an update with the new Xcode and swift.这是新 Xcode 和 swift 的更新。 Whenever you have addSubview(), replace it with contentView.addSubview()每当您有 addSubview() 时,将其替换为 contentView.addSubview()

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

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