Hi,
I'm having an issue with implementing drag and drop in my table view. I've followed various tutorials out there but none of them seem to work.
First of all, I have my my table view set up with the delegate and outlet and all. Then in the class I define my drag type:
And then I register the drag type in awakeFromNib:
And then there are the 3 methods for drag and drop:
Basically the app will let you drag apps from the Finder into the table view, and the "addAppsFromArray" method will deal with adding the app info to the table view.
However this does not seem to work. When I drag an app into the table view the green + does not appear. I have put an NSLog in the beginning of each of the methods to see if they are being called, and I found out that none of them are being called.
I am confused as to what I should do next
Thanks
I'm having an issue with implementing drag and drop in my table view. I've followed various tutorials out there but none of them seem to work.
First of all, I have my my table view set up with the delegate and outlet and all. Then in the class I define my drag type:
Code:
#define AppDrag @"app"
And then I register the drag type in awakeFromNib:
Code:
[table registerForDraggedTypes:[NSArray arrayWithObject:AppDrag]];
And then there are the 3 methods for drag and drop:
Code:
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
{
NSLog(@"write rows with indexes");
return YES;
}
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
{
NSLog(@"validate drop");
NSPasteboard *pb = [info draggingPasteboard];
NSString * type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];
if(type != nil && [type hasSuffix:@"app"]){
return NSDragOperationGeneric;
}
return NSDragOperationNone;
}
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
row:(int)row dropOperation:(NSTableViewDropOperation)operation
{
NSLog(@"accept drop");
//Get the files from the drop
NSArray * files = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
[self addAppsFromArray:files];
if([applications count] > 0) return YES;
return NO;
}
Basically the app will let you drag apps from the Finder into the table view, and the "addAppsFromArray" method will deal with adding the app info to the table view.
However this does not seem to work. When I drag an app into the table view the green + does not appear. I have put an NSLog in the beginning of each of the methods to see if they are being called, and I found out that none of them are being called.
I am confused as to what I should do next
Thanks