Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > removeObjectsInArray removes everything?

removeObjectsInArray removes everything?
Thread Tools
Fresh-Faced Recruit
Join Date: Dec 2002
Status: Offline
Reply With Quote
Mar 31, 2004, 01:16 AM
 
I'm having problems with removeObjectsInArray. I'm just starting off with a new non-document based project trying to get the delete of selected rows in a tableView working and for some reason when I try to delete the selected rows, it clears out my whole array even when I only have 1 row selected to be deleted out of many items.

employeeArray which is a NSMutableArray is alloc-ed and init-ed in the -(id)init of the controller.

When they click add, I create new entries (NSMutableDictionary) in the employeeArray.

Below is my code for deleting and I can't seem to figure out what I'm missing?
Any help appreciated...

- (IBAction)deleteEmployeeid)sender
{

int status;
NSEnumerator *enumerator;
NSNumber *index;
NSMutableArray *tempArray;
id tempObject;

if ( [empTableView numberOfSelectedRows] == 0 )
return;

NSBeep();
status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected record(s)?", @"OK", @"Cancel", nil);

if ( status == NSAlertDefaultReturn ) {
enumerator = [empTableView selectedRowEnumerator];
tempArray = [NSMutableArray array];

while ( (index = [enumerator nextObject]) ) {
tempObject = [employeeArray objectAtIndex:[index intValue]];
[tempArray addObject:tempObject];
}

[employeeArray removeObjectsInArray:tempArray];
[empTableView reloadData];
}
}
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Mar 31, 2004, 01:35 AM
 
have you checked to see if it's the enumerator that's giving you too many objects instead of the mutableArray that's removing too many? (like, print how many objects are in tempArray before calling removeObjects)
     
Fresh-Faced Recruit
Join Date: Dec 2002
Status: Offline
Reply With Quote
Apr 2, 2004, 11:23 PM
 
I just realized after a few minutes after re-reading the documents on NSMutableArray
that removeObjectsInArray uses isEqual: and isEqual: is defined to be as "a container object might define two containers as equal if their corresponding objects all respond YES to an isEqual: request" and I was preloading my NSMutableArray with objects with the same values. I then preloaded my NSMutableArray with different values and then ran the code again and worked as expected.

I should read the documents a little more slowly....

Thanks for the reply...


Originally posted by Uncle Skeleton:
have you checked to see if it's the enumerator that's giving you too many objects instead of the mutableArray that's removing too many? (like, print how many objects are in tempArray before calling removeObjects)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:05 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2