gpt4 book ai didi

ios - UITextView - 使用在 UITableViewCell() 中选择的所有文本开始编辑

转载 作者:搜寻专家 更新时间:2023-11-01 06:34:42 28 4
gpt4 key购买 nike

我有一个带有对象 TaskCell 的 tableView,它是 UITableViewCell 的子类

textView 位于 TaskCell 中,一切正常,除了我无法让这行代码选择 TextView 中的所有文本,以便用户可以立即覆盖如果他们愿意的话。就像您在按住文本后点击“全选”一样。

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
}

最佳答案

你有两个选择:

 [yourtextView selectAll:nil];        //highlights text
[yourtextView selectAll:self]; //highlights text and shows menu(cut copy paste)

在你的情况下,这将解决它:

- (BOOL)textViewDidBeginEditing:(UITextView *)textView {
dispatch_async(dispatch_get_main_queue(), ^{
[textView selectAll:nil];
});
return YES;
}

swift 3.0

func textViewDidBeginEditing(_ textView: UITextView) {
DispatchQueue.main.async {
textView.selectAll(nil)
}
}

enter image description here

关于ios - UITextView - 使用在 UITableViewCell() 中选择的所有文本开始编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42801919/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com