I can't get my head around this: I have an instance of NSMutableArray
filled with custom Lesson
objects. These objects have two properties
: name
and selected
. I'm trying to use these Lesson
objects in an NSTableView
. One column should show the name
as a string, the other selected
as check box. I used the
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
method to return the name, which worked fine, however returning the value of selected
doesn't work as expected - probably because the method gets called too often.
SO, can this be solved easily using the data source method or should I use Interface Builder and set up some bindings? 开发者_Go百科The latter sounds better, however I don't know how I could bring my setup - NSArray
with custom objects - into IB.
I would appreciate some ideas, Fabian
It seems that bindins would work pretty good in your case. You should use a NSArrayController binding to your array of Lesson's objects, lets call it "lessonsArray". Select the NSArray controller and set its "Model Key Path" to "lessonsArray". You must to create setter and getter to the "lessonsArray", otherwise it won't work.
Once you have put bindings to the NSArrayController, you have to bind the your NSTableView to it. In the reality, what you really need to bind now is the NSTableColumns, and I suppose you have two: name and selected. Bind them to the NSArrayController with this configuration: Controller Key: arrangedObjects Model Key Path: name or selected.
I hope that I've understood and helped you. Good luck
精彩评论