objective-c - NSTextView,绑定(bind)和显示 NSString

标签 objective-c xcode macos cocoa

我使用 Cocoa 的第二天。我已经设置了一个 NSTextView,它的属性字符串绑定(bind)到一个 NSArrayController(我正在使用核心数据):

controller key: selection
model key path: myString

我读到 NSTextView 需要 NSAttributedString,这就是它在尝试设置属性值时抛出异常的原因。

NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "myString"; desired type = NSString; given type = NSConcreteAttributedString; 

有什么想法可以让我的 managedObject 的 NSString 属性显示在 NSTextView 中吗?

最佳答案

您可以将 NSString 绑定(bind)到 NSTextView 的 value 而不是 attributedString。为此,您需要关闭 NSTextView 的“富文本”。

关于objective-c - NSTextView,绑定(bind)和显示 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7544236/

相关文章:

ios - PrepareForSegue 没有传递所有数据?

ios - 在 SpriteKit 游戏中设置为默认值的新 SKScene 结果为空白

html - 相同数量的像素在不同操作系统中渲染不同

java - osx maven 运行测试异常 : java. lang.OutOfMemoryError 从线程 "main"中的 UncaughtExceptionHandler 抛出

macos - biopython 安装测试失败 : ERROR: test_fetch_xml_schemas (test_Entrez_online. EntrezOnlineCase)

objective-c - 变量是静态的,无需声明,所以,OSX iOS Apple 风格的 C 或 Obj-C?

objective-c - CGContextDrawImage 导致 EXC BAD ACCESS

ios - UIButton 文本和图像

iphone - xCode/在类中声明静态方法

Xcode 9 : "An error occurred uploading to the iTunes Store."