How to select "child" entities in subview?

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-05-06T21:19:14Z Indexed on 2010/05/06 21:48 UTC
Read the original article Hit count: 145

Filed under:
|

I am trying to manage a drill-down list of data. I've got an entity, Contact, that has a to-many relationship with another entity, Rule. In my root view controller, I use a fetched results controller to manage and display the list of Contacts. When a Contact is tapped, I push a new view controller onto the stack with a list of the Contact's Rules.

I have not been able to figure out how to use a second fetched results controller to display the Rules, so I'm using the following:

// create a set of the contact's rules
rules = [NSMutableSet set];
rules = [self.contact mutableSetValueForKey:@"rule"];

// create an array of rules from the set
arrayOfRules = [NSMutableArray arrayWithCapacity:[rules count]];
for (id oneObject in rules)
     [arrayOfRules addObject:oneObject];

// sort the array of rules
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"phoneLabel" ascending:YES];
[arrayOfRules sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];
[descriptor release];

I create a set of Rules, then use that to create an array of Rules for sorting. I then use these two collections to populate the grouped table view. All of this appears to be working correctly.

Here's my problem: There are several different actions a user can take in this view, and most of them require that I know which Rule was tapped. But I can't figure out how to get that. For instance, say a user wants to delete a Rule. It seems to me the proper approach is something like...

[rules removeObject:ruleObjectToBeRemoved]

...but I can't figure out how to specifiy ruleObjectToBeRemoved. I hope all of this makes sense.

As usual, thanks in advance for any advice you can offer.

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about core-data