Cocoa中有哪些绑定选项?

时间:2015-04-13 14:49:16

标签: macos cocoa binding

值得一提的是,在以编程方式设置绑定时,值得检查IB中的等效绑定并确保将所有相同的设置传递给程序绑定。例如,我在IB中看到,默认情况下,对于NSTextView的Attributed String绑定,都会选中“允许编辑多个值选择”,“有条件地设置可编辑”和“引发不适用键”选项。这意味着我们的程序化绑定应该看起来像:

NSArray *keys = [NSArray arrayWithObjects:@"First Name", @"Address", nil];
NSArray *objects = [NSArray arrayWithObjects:@"vivek kumar", @"Vivek Bhavan", nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects 
                                                       forKeys:keys];

[textview bind: NSAttributedStringBinding 
      toObject: obj 
   withKeyPath: @"text" 
       options: dictionary];

我们可以在选项中使用NSDictionary绑定值吗?我们将使用函数获取值。或者它可以用于通过核心数据库更新TextField中的数据

1 个答案:

答案 0 :(得分:0)

Apple的文档告诉您哪些绑定可用于给定视图,以及哪些选项可用于特定绑定。 This is the relevant page for the NSTextView,这是NSAttributedString绑定页面上的选项表。

enter image description here

据我所知,您无法为此词典指定自定义键 - 而是仅限于'绑定选项列'下记录的键。同样,与每个键相关联的type没有余地 - 这是由Apple定义的,可以在相应的'Value class'中找到柱。

相关问题