I am having a problem with my textField, I have done everything possible but I'm not sure what the problem is, I need to get the updated value of textField. Attached below is the implementation of my custom 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")
}
}
This is wrong if it is implemented awakeFromNib
, it will not be a part of ViewController and only be a part of custom cell, the textfield is in table. It should be in cellForRow
...
cell.snippetParameter.delegate = self
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.