Re: newbie question on 'Cocoa Programming for Mac OS X'
Re: newbie question on 'Cocoa Programming for Mac OS X'
- Subject: Re: newbie question on 'Cocoa Programming for Mac OS X'
- From: email@hidden
- Date: Thu, 7 Feb 2002 18:35:03 -0500
Try:
http://www.bignerdranch.com/Book/Guide.html
On Thursday, February 7, 2002, at 06:23 PM, Richard Chamberlain wrote:
Hi,
I'm just working my way through 'Cocoa Programming for Mac OS X' and
would like some feedback on something.
At the end of chapter 5 there are two challenges - the second one is to
delete multiple items out of a NSMutableArray, the issue being that as
you Enumerate through them the indexes shift.
I've solved it in the following way:
- (IBAction) deleteEmployee:(id) sender
{
NSNumber *anIndex;
int aRow;
NSMutableArray *tempArray=[[NSMutableArray alloc]init];
NSEnumerator *e=[tableView selectedRowEnumerator];
while (anIndex=[e nextObject]) {
aRow=[anIndex intValue];
[tempArray addObject:[employees objectAtIndex:aRow]];
}
[employees removeObjectsInArray:tempArray];
[tempArray release];
[self updateUI];
}
It seems to work - but I was curious if there was a better pattern, and
whether I've made any basic deallocation mistakes.
Sorry if this is off-topic but I don't know anywhere that it would be
more on topic.
Thanks,
Richard
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.