设置NSTextView

use*_*819 7 cocoa nstextview nsattributedstring

我怎样才能设置NSTextViewNSAttributedString?我不想使用textConainer,我试过:

[myTextView insertText:myMutableAttributedString];
Run Code Online (Sandbox Code Playgroud)

但它不起作用.什么都没发生......甚至没有警告或运行时错误.任何帮助,将不胜感激.

est*_*art 14

必须可编辑Textview才能插入.

[myTextView setEditable:YES];
[myTextView insertText:myMutableAttributedString];
[myTextView setEditable:NO];
Run Code Online (Sandbox Code Playgroud)


ind*_*gie 3

在调用该方法之前,您应该-setString使用空字符串进行调用(否则您将向空字符串对象插入文本):

[myTextView setString:@""];
[myTextView insertText:myMutableAttributedString];
Run Code Online (Sandbox Code Playgroud)