I've got an team (eveningRoster) that I'm making a button add employees to. The team is really a relationship to that night's event, but it's represented with an AC.
I wanted to make sure an employee did not belong to the team before it adds, so I added a method to MyDocument to check first. It seems to work, the error logs complete, but after I've added a member, the next time I click anything, the program crashes. Any guesses why? Here's the code:
-(IBAction)playsTonight:(id)sender
{
NSArray *selection = [fullRoster selectedObjects];
NSArray *existing = [eveningRoster arrangedObjects];
//Result will be within each loop.
BOOL result;
//noDuplicates will stay YES until a duplicate is found.
BOOL no开发者_高级运维Duplicates = YES;
//For the loop:
int count;
for (count = 0; count < [selection count]; count++){
result = [existing containsObject:[selection objectAtIndex:count]];
if (result == YES){
NSLog(@"Duplicate found!");
noDuplicates = NO;
}
}
if (noDuplicates == YES){
[eveningRoster addObjects:[fullRoster selectedObjects]];
NSLog(@"selected objects added.");
[eveningTable reloadData];
NSLog(@"Table reloaded.");
}
[selection release];
[existing release];
return;
}
Assuming that -selectedObjects and -arrangedObjects are the standard NSController methods, these are returning auto-released objects (or, at the very least, objects that YOU are not responsible for releasing). If you remove those last two -release calls in your method, it should fix that problem.
精彩评论