• 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's contentArray and selectedIndexes don't match when sorted
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController's contentArray and selectedIndexes don't match when sorted


  • Subject: Re: NSArrayController's contentArray and selectedIndexes don't match when sorted
  • From: mmalcolm crawford <email@hidden>
  • Date: Sun, 5 Mar 2006 21:29:43 -0800


On Mar 5, 2006, at 5:14 PM, Greg Herlihy wrote:

Unfortunately, this binding between your variable and the NSArrayController
leaves no room for the table at all. So whatever is selected in the table
changes nothing about the selection in the NSArrayController (or in its
bound variable). So there is no reason to expect that the selection in the
table would match the selection in the NSArrayController, because no binding
exists between them. [...]

It's not entirely clear what this means (written with some trepidation after the previous misreading...).


The selectionIndexes array does contain the indexes of the items selected in the table view. The table view though shows the array controller's arrangedObjects, so the selection indexes correspond to the indexes in arrangedObjects.

If you managed the content array, you can also bind 'sortDescriptors' and retrieve the actual selected objects using:

NSArray *sortedArray = [contentArray
sortedArrayUsingDescriptors:[self sortDescriptors]];

NSArray *selectedObjects = [sortedArray objectsAtIndexes:[self selectionIndexes]];


If you have a predicate, then you need to bind and managed 'filterPredicates' and filter the array using the predicates array as well.

This all assumes you're not using a custom subclass of NSArrayController that overrides 'arrangedObjects'...

This all seems like a "lot" of work just to avoid using an outlet. It probably bears repeating that Cocoa bindings does not *replace* all the techniques available...

mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: NSArrayController's contentArray and selectedIndexes don't match when sorted (From: Greg Herlihy <email@hidden>)

  • Prev by Date: Re: Fastest Datastore?
  • Next by Date: Subclassed tableView no longer responding to draggingEntered
  • Previous by thread: Re: NSArrayController's contentArray and selectedIndexes don't match when sorted
  • Next by thread: Re: NSArrayController's contentArray and selectedIndexes don't match when sorted
  • Index(es):
    • Date
    • Thread