Re: Setting the source of an NSArrayController from more than one other controller
Re: Setting the source of an NSArrayController from more than one other controller
- Subject: Re: Setting the source of an NSArrayController from more than one other controller
- From: email@hidden
- Date: Mon, 3 Oct 2005 17:56:15 -0500
In my example, I have an array controller which connects with a
search field to arrange objects which match the search text (possibly
narrowed to selected criteria). Then I added another controller with
group objects (sessions) which relate records; I wanted to be able to
narrow the table view based on selected group(s) as well as the
search results. Searching is handled by overriding -arrangeObjects;
so I added a filtering method that scopes the array input to -
arrangeObjects based on the group(s) selected, and then searches the
resulting array. Note that the first array controller has an outlet
to the second one in order to get its selection.
- (NSArray *)filterObjectsBySession:(NSArray *)objects
{
NSArray *selectedSessions = [sessionsController selectedObjects];
unsigned sessionCount = [selectedSessions count];
if ( !sessionCount )
return objects;
else {
NSMutableArray *newObjects = [NSMutableArray
arrayWithCapacity: [objects count]];
NSEnumerator *enumerator = [objects objectEnumerator];
MyRecord *record;
// return only the records which related to one of the
selected sessions in the
// session array controller
while ( record = [enumerator nextObject] )
if ( [selectedSessions containsObject: [record session]] )
[newObjects addObject: record];
return newObjects;
}
}
- (NSArray *)arrangeObjects:(NSArray *)objects
{
NSArray *filteredObjects = [self filterObjectsBySession: objects];
// searchString is set by the search field's action
if ( !searchString || [searchString isEqualToString: @""] )
return [super arrangeObjects: filteredObjects];
NSMutableArray *newObjects = [NSMutableArray arrayWithCapacity:
[filteredObjects count]];
NSEnumerator *enumerator = [filteredObjects objectEnumerator];
MyRecord *record;
// now iterate through the objects and add to the result those
which match the search criteria
while ( record = [enumerator nextObject] ) {
// and so on...
On Sep 26, 2005, at 8:09 PM, Alexander Lamb wrote:
Date: Mon, 26 Sep 2005 23:06:54 +0200
From: Alexander Lamb <email@hidden>
Subject: Setting the source of an NSArrayController from more than one
other controller
To: Cocoa-Dev Mail <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Hello,
I would like to have an NSArrayController represent a list of
objects which are filtered not only from one master controller
(like in the example of the documentation) but from two. Indeed, it
is like "get all the objects where attribute A comes from what is
selected in controller A and attribute B comes from what is
selected in controller B".
Is it possible to do that somewho from interface builder or will I
have to build an NSArray using a custom search to populate the
detail controller?
If so, what is the best way to have the detail controller ask for
the arrangedObjects again each time a selection changes in one of
the master controllers?
_______________________________________________
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