Re: binding an array controller to columns in an NSTableView
Re: binding an array controller to columns in an NSTableView
- Subject: Re: binding an array controller to columns in an NSTableView
- From: Chuck Soper <email@hidden>
- Date: Tue, 11 Sep 2012 10:13:29 -0700
- Thread-topic: binding an array controller to columns in an NSTableView
On 9/10/12 7:15 PM, "Quincey Morris" <email@hidden>
wrote:
>On Sep 10, 2012, at 18:40 , Chuck Soper <email@hidden> wrote:
>
>> I understand how to bind an array controller (for an entity) to rows in
>>a
>> table, and how to bind a Text Field in the Table Cell View to an entity
>> property. I'm not sure how to go about this for columns in a table. I
>> assume that I may need to take a programmatic approach. Has anyone done
>> this? Or, can someone point me in the right direction?
>
>You can't do this with bindings. Tables are row-oriented, and there's no
>built-in behavior that will add or remove columns like it does for rows.
>
>If your colors have a name, you could (programmatically) create a column
>for each existing column name, using the name as the column identifier,
>which should ease the problem of matching columns to colors. You'll also
>need a way of deciding what order to show the columns in. Then you can
>use something like KVO to watch for changes in the set of colors, and
>make corresponding adjustments to the table.
Thanks for this advice. I need to extend this question a bit. Let's say my
data model has two entities, House and Color. A house has one or more
colors.
Entities for my data model:
House: Attributes: name; Relationships: colors (to-many).
Color: Attributes: name; Relationships: house.
At the moment, both relationships are marked as Optional, but I think I
need to change that so that neither are Optional because a house always
has at least one color.
When adding additional colors, I understand that the following code can
create a color object, but I'm not sure where to put this code or if I can
use bindings instead.
NSManagedObject *color = [NSEntityDescription
insertNewObjectForEntityForName:@"Color"
inManagedObjectContext:self.managedObjectContext];
[color setValue:@"Dark Blue" forKey:@"name"];
Essentially, I want each "color" object to be a bindable custom view.
Ideally, this custom view would be a NSTableCellView subclass. My table
would always have a single row, so I misspoke when I described that as a
column. I'm not sure how I create and remove this view when creating and
removing color objects.
I think that Tim Isted's "A Bindable Custom NSView Subclass" blog post is
close to what I'm looking for, but I haven't completely digested the
article.
http://www.timisted.net/blog/archive/a-bindable-custom-nsview-subclass/
Thanks for any tips or advice people have.
Chuck
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden