如何处理 TextField 的 shouldChangeCharactersIn,如果它位于 TabelViewControler 的自定义单元格中
how to handle shouldChangeCharactersIn for a TextField, if it is located in the Custom Cell in the TabelViewControler
我看不懂。怎么做,试过这个:
class myViewCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var myEdit: UITextField!
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// don`t work ((
}
}
class myTableViewControler: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NamePhoneCell", for: indexPath) as! myViewCell
…
returns cell
}
}
我有一个想法 - Delegete。但是,我需要如何委托 UITableViewCell 本身从 UITextFieldDelegate
委托的 -shouldChangeCharactersIn 方法
您没有将 UITextField 委托分配给 myViewCell
加入myViewCell
class下一个:
override func awakeFromNib() {
super.awakeFromNib()
myEdit.delegate = self
}
您需要为您创建的 UITextField 设置委托。
myViewCell 将实现您的 UITextField 的委托函数。
class myViewCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var myEdit: UITextField!
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// don`t work ((
}
}
override func awakeFromNib() {
super.awakeFromNib()
myEdit.delegate = self
}
我看不懂。怎么做,试过这个:
class myViewCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var myEdit: UITextField!
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// don`t work ((
}
}
class myTableViewControler: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NamePhoneCell", for: indexPath) as! myViewCell
…
returns cell
}
}
我有一个想法 - Delegete。但是,我需要如何委托 UITableViewCell 本身从 UITextFieldDelegate
委托的 -shouldChangeCharactersIn 方法您没有将 UITextField 委托分配给 myViewCell
加入myViewCell
class下一个:
override func awakeFromNib() {
super.awakeFromNib()
myEdit.delegate = self
}
您需要为您创建的 UITextField 设置委托。 myViewCell 将实现您的 UITextField 的委托函数。
class myViewCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var myEdit: UITextField!
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// don`t work ((
}
}
override func awakeFromNib() {
super.awakeFromNib()
myEdit.delegate = self
}