![](/img/trans.png)
[英]Swift 3: retrieving text from a UITextField in a custom UITableViewCell
[英]Swift Select all text of a UITextfield from UITableviewCell Class
我想在UITableviewCell
里面的UITextField
选择所有文本。 但是我在这里找到的每个解决方案都行不通。 它从不选择我点击的UITextfield
的文本。
这是我的代码(简体)。 有人知道问题可能在哪里吗?
class generalTextFieldTableViewCell: UITableViewCell {
@IBOutlet weak var textField: UITextField!
@IBAction func textFieldDidBeginEditing(sender: UITextField) {
sender.becomeFirstResponder()
sender.delegate = self.textField.delegate
sender.selectAll(self)
}
}
在cellForRowAtIndexPath
,使用当前的ViewController
设置textField
的委托,并尝试使用UITextField
textFieldDidBeginEditing
委托方法。
func textFieldDidBeginEditing(textField: UITextField) {
textField.selectAll(nil)
}
注意:不要忘记像这样的cell.textField.delegate = self
那样在cellForRowAtIndexPath
内部设置textField
委托。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.