开发者

After I apply custom logic, next UI action crashes my app

开发者 https://www.devze.com 2022-12-22 17:24 出处:网络
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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消