【发布时间】:2017-03-15 05:45:01
【问题描述】:
我有一个带有对象TaskCell 的tableView,它是UITableViewCell 的子类
textView 在TaskCell 中,一切正常,除了我无法让这行代码选择文本视图中的所有文本,因此用户可以根据需要立即覆盖文本。就像您在按住文本后点击“全选”一样。
textView.selectedTextRange = textView.textRange(from: textView.beginningOfDocument, to: textView.endOfDocument)
_
// All code relating to textView
class TaskCell: UITableViewCell {
@IBOutlet weak var textView: UITextView! { didSet { initTextView() } }
fileprivate func initTextView() {
textView.delegate = self
}
}
extension TaskCell: UITextViewDelegate {
func textViewDidBeginEditing(_ textView: UITextView) {
textView.selectedTextRange = textView.textRange(from: textView.beginningOfDocument, to: textView.endOfDocument)
}
}
// class ListViewController: ViewController, UITableViewDataSource, UITableViewDelegate
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TaskCell
return cell
}
【问题讨论】:
标签: ios swift uitextview uitextviewdelegate