Re: NSArrayController selection for remove: ... how does it know?
Re: NSArrayController selection for remove: ... how does it know?
- Subject: Re: NSArrayController selection for remove: ... how does it know?
- From: "I. Savant" <email@hidden>
- Date: Tue, 29 Jul 2008 12:28:17 -0400
> 'Delete' however I don't understand. Hitting the button triggers the remove:
> action in the NSArrayController which deletes the selected entry from the
> NSMutableArray but ... how does it know which one to delete? I haven't told
> the NSArrayController what NSTableView it's attached to, or if it's attached
> to one at all.
The easy explanation first: You told the table columns what to
observe (the array controller's arranged objects array). In the
background, this automatically binds the table's selection to the
array controller's own selection. When the table's selection changes,
so does the array controller's (and vice-versa).
To test this, create a second table and bind it the same way as the
first. Now select different rows in each table and observe how the new
selection in one table is mirrored by the other. This is because the
'common factor' is that they're both bound to the array controller's
selection.
> [ Supplementary question - when used in 'hand written' code you supply a
> dataSource for the NSTableView. When used with bindings, that's nil. I
> wondered how that worked too. If there is a nil dataSource does the
> underlying implementation of the NSTableView assume its NSTableColumns are
> bound and basically becomes its own dataSource? ]
No, not really. The NSTableView knows enough to realize when to use
bindings or a data source (if either are present). For the record, you
can use a mix of bindings and the NSTableDataSource protocol.
--
I.S.
_______________________________________________
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