• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSArrayController selection for remove: ... how does it know?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController selection for remove: ... how does it know?


  • Subject: Re: NSArrayController selection for remove: ... how does it know?
  • From: Roland King <email@hidden>
  • Date: Wed, 30 Jul 2008 00:48:14 +0800


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@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


References: 
 >NSArrayController selection for remove: ... how does it know? (From: Roland King <email@hidden>)
 >Re: NSArrayController selection for remove: ... how does it know? (From: "I. Savant" <email@hidden>)

  • Prev by Date: help about the flat-namespace?
  • Next by Date: Re: [Newbie] Communication between two Views?
  • Previous by thread: Re: NSArrayController selection for remove: ... how does it know?
  • Next by thread: help about the flat-namespace?
  • Index(es):
    • Date
    • Thread