![](/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.