Cocoa Binding Mutable Dictionary with Search Field

可紊 提交于 2019-11-29 05:19:50

(1)Which should I use? NSObjectController, NSDictonaryController, or NSTreeController.

Use NSDictionaryController.

(2)How should I bind the controller to the dictionary? Is there a "key" and a "value" that I can bind or do I have to use properties declared in another class and add it to the dictionary?

Step 1 : Create @property(strong)NSMutableDictionary *dict; in .h file

Step 2 : Create a NSDictionaryController.

Step 3 : Check prepares content.

Step 4 : Set as :

Step 5 : Create a NSTableView.

Step 6 : For first column do as:

Step 7 : similarly for second column put value in Model Key Path.

Find the running sample here.

(3)Can I bind that into a NSTableView with a "Key" on one side and a "value" on another side?

Already done.

Binding NSDictionaryController with NSTableView by NSSearchField

Step 1 : Draw a NSSearchField.

Step 2 : Bind it to NSDicitonaryController in Predicate option.

Step 3 : In predicate format put key contains $value

As your Second Question is :

NSString *myListPath = [[NSBundle mainBundle] pathForResource:@"Collection" ofType:@"plist"]; self.Dictionary1 = [[NSMutableDictionary alloc]initWithContentsOfFile:myListPath];

And I access one of them by :

NSString *initialString = [[_Dictionary1 valueForKey:@"Book1"]objectForKey:@"1"];

You can use :

NSString *book=@"Book1";
NSString *chapter=[book integerValue];
NSString *initialString=self.Dictionary1[book][chapter];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!