views:

33

answers:

1

I am working on an app that is not core data based - the data feed is a series of web services.

Two arrays are created from the data feed. The first holds season data, each array object being an NSDictionary. Two of the NSDictionary entries hold the data to be displayed in the popup ('seasonName') and an id ('seasonID') that acts as a pointer (in an external table) by matches defined for that season.

The second array is also a collection of NSDictionaries. Two of the entries hold the data to be displayed in the popup ('matchDescription') and the id ('matchSeasonId') that points to the seasonId defined in the NSDictionaries in first array.

I have two NSPopUps. I want the first to display the season names and the second to display the matches defined for that season, depending on the selection in the first.

I'm new at bindings, so excuse me if I've missed something obvious. I've tried using ArrayControllers as follows:

SeasonsArrayController: content bound to appDelegate seasonsPopUpArrayData.

seasonsPopup: content bound to SeasonsArrayController.arrangedObjects; content value bound to SeasonsArrayController.arrangedObjects.seasonName

I see the season names fine. I can obviously follow a similar route to see the matches, but I then see them all, instead of restricting the list to the matches for the season highlighted.

All the tutorials I can find seem to revolve around core data and utilise the relationships defined therein. I don't have that luxury here. Any help very gratefully received.

A: 

This is not an answer - more an extension of the previous problem.

I created MatchesArrayController and subclassed it from NSArrayController to allow some customisation.

Following the example in 'Filtering Using a Custom Array Controller' from 'Cocoa Bindings Topics', I followed the same idea as above: MatchessArrayController: content bound to appDelegate matchesPopUpArrayData.

matchesPopup: content bound to MatchesArrayController.arrangedObjects; content value bound to MatchesArrayController.arrangedObjects.matchDescription.

I've derived the selected item from seasonPopUp:sender and used this to identify the seasonId. The idea is to change the arrangedObjects in MatchesArrayController by defining the following in;

- (NSArray *)arrangeObjects:(NSArray *)objects
{
    if (searchString == nil) {
        return [super arrangeObjects:objects];
    }

    NSMutableArray *filteredObjects = [NSMutableArray arrayWithCapacity:[objects count]];
    NSEnumerator *objectsEnumerator = [objects objectEnumerator];
    id item;

    while (item = [objectsEnumerator nextObject]) {
        if ([[[item valueForKeyPath:@"matchSeasonId"] stringValue] rangeOfString:searchString options:NSAnchoredSearch].location != NSNotFound) {
            [filteredObjects addObject:item];
        }
    }
    return [super arrangeObjects:filteredObjects];
}

- (void)searchWithString:(NSString *)theSearchString {
    [self setSearchString:theSearchString];
    [self rearrangeObjects];
}

- (void)setSearchString:(NSString *)aString
{
   [aString retain];
    [searchString release];
    searchString=aString;
}

I've used NSLog to check that things are happening the way they are supposed to and all seems ok. However, it still doesn't do what I want.

[self rearrangeObjects]; is supposed to invoke the arrangeObjects method but doesn't. I have to call it explicity (i.e.[matchesArrayController arrangeObjects:matchesPopUpArrayData]; )

Even then, although filteredObjects gets changed the way it is supposed to, the drop down list does not get updated the way I want it to.