On Jul 30, 2008, at 12:28 AM, I. Savant wrote:

'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.

thanks I.S. and Felix. Felix pointed out the one line in the documentation I probably wouldn't have recognised as vital. I did that second table trick whilst trying to figure it out, but didn't understand the relevance.

My misunderstanding here was thinking that the NSArrayController/ NSTableView were very generic total standalone objects and all their hookups would be done very explicitly. Now I see there's some expectations about NSArrayController/NSTableView being paired with each other and a number of bindings are set up behind the scenes to make things behave by default as you'd expect.

perhaps what I should have done is subclass the NSArrayController and NSLog the bind: and addObserver: messages, that might have given me a hint as to where to look.



_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to