Ios UITextView-在UITableViewCell()中选择所有文本后开始编辑

Ios UITextView-在UITableViewCell()中选择所有文本后开始编辑,ios,swift,uitextview,uitextviewdelegate,Ios,Swift,Uitextview,Uitextviewdelegate,我有一个tableView,其中有一个对象TaskCell,它是UITableViewCell textView位于TaskCell中,一切正常,但我无法使用这行代码选择文本视图中的所有文本,因此用户可以在需要时立即覆盖文本。就像在按住文本的点击按钮后点击“全选”一样 textView.selectedTextRange = textView.textRange(from: textView.beginningOfDocument, to: textView.endOfDocument) _

我有一个tableView,其中有一个对象
TaskCell
,它是
UITableViewCell

textView
位于
TaskCell
中,一切正常,但我无法使用这行代码选择文本视图中的所有文本,因此用户可以在需要时立即覆盖文本。就像在按住文本的点击按钮后点击“全选”一样

textView.selectedTextRange = textView.textRange(from: textView.beginningOfDocument, to: textView.endOfDocument)
_

您有两个选择:

 [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)
    }
}
您有两个选择:

 [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)
    }
}

它对我来说很简单,你应该在你的情况下应用它,例如在textViewDidChange中,只要我键入某个内容,它就会突出显示所有文本。但不是在textViewDidBeginEditing中。DispatchQueue.main.async修复了它!在应该开始编辑的情况下,它在textViewDidEndEditing上造成了一些奇怪的无限循环错误。再次感谢@Alsh compilerit,它与我一起工作过,你应该在你的情况下应用它,例如在textViewDidChange中,只要我键入一些内容,它就会突出显示所有文本。但不是在textViewDidBeginEditing中。DispatchQueue.main.async修复了它!在应该开始编辑的情况下,它在TextViewDiEndediting上导致了一些奇怪的无限循环错误。再次感谢@Alsh编译器