| Article: |
Working with Tables: Writing an Address Book Application | |
| Subject: | Works but with a little bug | |
| Date: | 2005-06-19 17:24:01 | |
| From: | jz87 | |
| I'm running this on XCode 2.1 that came with Tiger, and there seems to be a slight bug with delete version 4. If you have any duplicate records, if you select any one of the copies and delete, it'll delete all the copies. | ||
Showing messages 1 through 1 of 1.
-
Ok fixed it
2005-06-19 17:49:39 jz87 [View]



- (IBAction)deleteRecord:(id)sender
{
int status;
NSEnumerator* enumerator;
NSNumber* index;
NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
if ([tableView numberOfSelectedRows] == 0)
return;
NSBeep();
status = NSRunAlertPanel(@"Warning!", @"Are you sure you want to delete the selected record(s)?", @"OK", @"Cancel", nil);
if (status == NSAlertDefaultReturn)
{
enumerator = [tableView selectedRowEnumerator];
while (index = [enumerator nextObject])
{
[indexSet addIndex:[index intValue]];
}
[records removeObjectsAtIndexes:indexSet];
[tableView reloadData];
}
}
The documentation says that NSMutableIndexSet is only available since Panther. The remove object from array probably removes all matching objects, so it would remove all duplicates of an entry even if you just selected one. This version only removes the entries that were actually selected.