Cocoa 设置NSTextView
如何将Cocoa 设置NSTextView,cocoa,nstextview,nsattributedstring,Cocoa,Nstextview,Nsattributedstring,如何将NSTextView设置为nsattributed字符串?我不想使用textConainer,我尝试了: [myTextView insertText:myMutableAttributedString]; 但它不起作用。没有发生任何事情…甚至没有警告或运行时错误。任何帮助都将不胜感激。在调用该方法之前,您应该使用空字符串调用-setString(否则您将在空字符串对象中插入文本): Textview必须可编辑才能插入 [myTextView setEditable:YES]; [myT
NSTextView
设置为nsattributed字符串
?我不想使用textConainer,我尝试了:
[myTextView insertText:myMutableAttributedString];
但它不起作用。没有发生任何事情…甚至没有警告或运行时错误。任何帮助都将不胜感激。在调用该方法之前,您应该使用空字符串调用
-setString
(否则您将在空字符串对象中插入文本):
Textview必须可编辑才能插入
[myTextView setEditable:YES];
[myTextView insertText:myMutableAttributedString];
[myTextView setEditable:NO];
文本视图是以编程方式创建的吗?如果您从xib加载NSTextView,它将正常工作。在Swift 2.2中:
myTextView.textStorage?.SetAttributeString(MyMutableAttributeString)
在目标C中:
[[myTextView textStorage]setAttributedString:myMutableAttributedString]代码>您是否验证了myTextField
不是nil
?是的,我验证了myTextView不是nil。它不起作用。甚至没有任何在控制台中报告问题的内容不推荐使用“insertText:”:首先在macOS 10.11中不推荐使用-使用-insertText:replacementRange:“从客户端”。由于该方法被设计为仅由输入系统使用,因此不应将消息从应用程序发送到文本视图。任何内容修改都应通过NSTextStorage或NSText方法进行。
[myTextView setEditable:YES];
[myTextView insertText:myMutableAttributedString];
[myTextView setEditable:NO];