• 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
Difficulty adding and removing objects from "nested" NSArrayControllers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Difficulty adding and removing objects from "nested" NSArrayControllers


  • Subject: Difficulty adding and removing objects from "nested" NSArrayControllers
  • From: "Fletcher T. Penney" <email@hidden>
  • Date: Sun, 29 May 2005 19:47:15 -0400

THE CONTEXT

I have a Core Data application that (for demo purposes) consists of objects with two attributes (firstName, lastName). I am building an iTunes-like interface to search through the database.


THE SETUP


An NSTreeController manages a set of FilterObjects - these are used to add and filter out objects (the analogy of playlists and smart playlists). They use AND and OR as appropriate to create arbitrarily complicated filter predicates to choose a subset of all the people to display in a table.



In order to coordinate these collections with the search bar, and with a series of single column tables that show the list of distinct first and last names and choose from them, I have created a series of NSArrayControllers that daisy chain the filterpredicates.



The NSArrayControllers are as follows: (all managedObjectContext's are set to the App Delegate, and all sortDescriptors are set to the sortDescriptor of DisplayPeople)


AllObjects - this controller contains all of the people. The "Add" button is connected here, as is the "Remove" button

CollectionFiltered - contentArray is bound to the arrangedObjects of AllObjects, filterPredicate is bound to selection.filterPredicate of the NSTreeController (the predicate is generated programmatically)

SearchBoxFiltered - contentArray is bound to arrangedObjects of CollectionFiltered, filterPredicate is created by the search box (default when option-dragged from XCode)

DisplayedPeople - contentArray is bound to arrangedObjects of SearchBoxFiltered, and there is no filterPredicate at this stage (a few more links in the chain will be created to filter based on firstName and lastName, as chosen from the single column tables of distinct names.)


Currently, selectionIndexes are linked in the reverse order as above (I have experimented with both directions, and this seems to work better)



THE PROBLEM

The above scenario works. I can simultaneously limit the display table based on the chosen filter ("Playlist"), by a query in the search box, and by chosen first and last names in respective lists. It's quite a flexible way of exploring a large set of data.

The problem is that when you have a subset of objects displayed in the table, removing a selected object does not work so well. For example, if you type a search query that produces 1 item out of 6 (say it happens to be last in the original list), and remove it, you instead remove the first item of the 6. In other words, by telling the table to remove object 1 of 1, you instead remove 1 of 6 (if there are a total 6 objects in the unfiltered view.)


THE QUESTION

Is it possible to daisy chain ArrayControllers as described above to allow multiple methods of filtering objects to applied in series without screwing up the add and remove functions?

If I try removing an object from the DisplayedPeople controller (the "last" in the chain), I get errors like:

2005-05-29 19:34:50.396 Filtering Example[20116] *** - [_NSControllerArrayProxy removeObjectAtIndex:]: selector not recognized [self = 0x3b8ea0]

It's not convenient to the user to remember to undo all filtering, and then delete the object from the table after all objects are available.

There's probably a better way of doing this, but other than this issue, it seems to be working. And it is fairly easy to extend the chain by a link in order to add another method of filtering as the program grows more complex.


I suppose another approach would be to create a single object that gathers all of the filterPredicates, AND combines them, and the sets the predicate for a single NSArrayController, but this would generate other problems, and would be less reusable....



TIA,

Fletcher

PS> I am in the midst of re-connecting everything after a first draft version, and once it's hooked-up I will release what I have for others to look at and use, but I would love to get all the quirky behavior worked out first...
_______________________________________________
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
  • Prev by Date: Re: "Arguments" dictionary in NSXML
  • Next by Date: Re: Tiger development Panther deployment
  • Previous by thread: Re: mainbundle and frameworks
  • Next by thread: Tiger Decoding problem
  • Index(es):
    • Date
    • Thread