[英]textFieldShouldReturn in custom UITableViewCell not working
我的 textField 有問題,我已盡一切可能,但我不確定問題出在哪里,我需要獲取 textField 的更新值。 下面附上我的自定義tableViewCell的實現:
import UIKit
class SnippetCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var snippetId: UILabel!
@IBOutlet weak var snippetParameter: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
snippetParameter.delegate = self
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
snippetParameter.layer.cornerRadius = 15
snippetParameter.clipsToBounds = true
// Configure the view for the selected state
}
func textFieldDidEndEditing(_ textField: UITextField) {
print("TextField did end editing method called")
snippetParameter.text = textField.text!
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
print("TEXT->",textField.text ?? "")
return true
}
func textFieldDidBeginEditing(_ textField: UITextField) {
print("TextField did begin editing method called")
}
}
如果實現awakeFromNib
這是錯誤的,它將不是 ViewController 的一部分,而只是自定義單元格的一部分,文本字段在表中。 它應該在cellForRow
...
cell.snippetParameter.delegate = self
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.