cocoa - 具有多个属性的模型关键路径

标签 cocoa core-data cocoa-bindings nsarraycontroller kvc

在这里,我使用 NSArrayController 将 Core Data 实体的属性绑定(bind)到 TextView 表格单元格的值。

enter image description here

我使用什么语法来访问模型键路径中实体的多个属性?

格式字符串示例:@"%@, %@", lastName, firstName;

最佳答案

在文本字段的绑定(bind)检查器中:

  1. 选择“带模式的值:显示模式值 1”
  2. 绑定(bind)到数组 Controller
  3. Controller 键 = 选择
  4. 模型键路径 = lastName
  5. 显示模式 = %{value1}@, %{value2}@
  6. 选择绑定(bind)检查器中现在可用的选项:“显示模式值 2”
  7. 将 Value2 绑定(bind)到 AC、选择firstName

这记录在 NSTextField section of the Cocoa Bindings Reference.

为了完整起见,这里是我自己的一些代码,我在其中以编程方式进行这种绑定(bind):

NSString* bannerPattern = @": %{value1}@ items found, %{value2}@ hidden %{value3}@";
NSString* totalPattern = [dateString stringByAppendingString:bannerPattern];

[ftview.textField bind:@"displayPatternValue1" toObject:ft withKeyPath:@"visibleNumber" options:@{NSDisplayPatternBindingOption : totalPattern}];
[ftview.textField bind:@"displayPatternValue2" toObject:ft withKeyPath:@"hiddenNumber" options:@{NSDisplayPatternBindingOption : totalPattern}];
[ftview.textField bind:@"displayPatternValue3" toObject:ft withKeyPath:@"newString" options:@{NSDisplayPatternBindingOption : totalPattern}];

关于cocoa - 具有多个属性的模型关键路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24456253/

相关文章:

ios - 如何在多个线程上处理 NSManagedObjectContext 和 NSManagedObject 创建和编辑?

html - 如何在 Cocoa 中将 RTF 文本转换为 Markdown 语法的纯文本?

core-data - 如何知道 NSPredicate 中抽象实体的类类型?

ios - 无法删除其他上下文中的对象

objective-c - 基于核心数据文档的基于选择的多个 Nib

cocoa - 使用 KVO 绑定(bind)到 bool 属性的负数

macos - 获取 NSStatusItem 的长度

swift - 将 NSViewController 设置为全屏

objective-c - 使用 Cocoa App 中嵌入的 AppleScript-ObjC 处理错误的最佳方法?

xcode - 在连接检查器中引用绑定(bind)