NSTableView Drag & Drop... Well, Maybe
NSTableView Drag & Drop... Well, Maybe
- Subject: NSTableView Drag & Drop... Well, Maybe
- From: mw <email@hidden>
- Date: Tue, 08 Oct 2002 09:20:34 -0400
Here is my implimentation for an NSTableView's acceptDrop method. It hates
me! For some reason, after I unarchive the NSData object back into array
form, I can't seem to access anything in the array (using objectAtIndex:)
because it gives me an EXEC_BAD_ACCESS signal.
- (BOOL)tableView:(NSTableView *)tv acceptDrop:(id <NSDraggingInfo>)info
row:(int)row dropOperation:(NSTableViewDropOperation)op
{
int i=0;
NSArray *unarchivedPeople;
NSMutableArray *peopleToRemove = [[NSMutableArray alloc] init];
NSPasteboard *pboard = [info draggingPasteboard];
NSData *archivedArray;
NSEnumerator *e = [tv selectedRowEnumerator];
NSNumber *index = [NSNumber numberWithInt:0];
NSString *type = [pboard availableTypeFromArray:[NSArray
arrayWithObject:MPWTableViewPboardType]];
// Check if the type is correct
if(type == MPWTableViewPboardType) {
// Gets all of the selected rows from the table and places their
objects into the array
// of people to remove (because we are moving, not copying).
while(index = [e nextObject]) {
[employees removeObjectAtIndex:[index intValue]];
}
// The type is correct, so we can get and unarchive the NSData
object
archivedArray = [pboard dataForType:MPWTableViewPboardType];
unarchivedPeople = [NSUnarchiver
unarchiveObjectWith
Data:archivedArray];
// Now we add this unarchived array to the employees array
e = [tv selectedRowEnumerator];
while(index = [e nextObject]) {
[employees insertObject:[unarchivedPeople objectAtIndex:i]
atIndex:[index intValue]];
i+=1;
}
[self updateChangeCount: NSChangeDone];
[self updateUI];
[peopleToRemove release];
return YES;
} else {
[peopleToRemove release];
return NO;
}
}
The problem seems to be in the second while loop:
// Now we add this unarchived array to the employees array
e = [tv selectedRowEnumerator];
while(index = [e nextObject]) {
[employees insertObject:[unarchivedPeople objectAtIndex:i]
atIndex:[index intValue]];
i+=1;
}
Because that is where the unarchived array from the pasteboard is accessed.
Anybody have any idea what I am doing wrong here? I am baffled.
mw
_______________________________________________
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.