3

Here, I'm using an NSArrayController to bind properties from Core Data entities into the value of text view table cells.

enter image description here

What syntax do I use to access multiple properties of the entity in the Model Key Path?

Example as a format string: @"%@, %@", lastName, firstName;

4

1 回答 1

4

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

  1. 选择“带模式的值:显示模式值1”
  2. 绑定到阵列控制器
  3. 控制器键 =selection
  4. 模型键路径 =lastName
  5. 显示模式 =%{value1}@, %{value2}@
  6. 选择绑定检查器中现在可用的:“显示模式值 2”
  7. 将 Value2 绑定到 AC, selection,firstName

这记录在Cocoa Bindings Reference 的 NSTextField 部分。

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

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}];
于 2014-06-28T20:06:10.707 回答