On Oct 26, 2011, at 10:20 PM, GW Rodriguez wrote:

> I am trying to limit files with certain UTI's from dropping into a table 
> view.  Here's my code so far:
> 
> // in the init method I set the registerForDraggedTypes with NSURLPboardType
> 
> -(NSDragOperation) tableView: (NSTableView*)tv 
>                 validateDrop: (id <NSDraggingInfo>)info 
>                  proposedRow: (int)row 
>        proposedDropOperation: (NSTableViewDropOperation)op 
> {    
> 
>     NSDragOperationdragOp = NSDragOperationCopy;
>     
>     // if drag source is self its a move unless the option key is pressed
>     if ([info draggingSource] == playlistView) {
>         NSEvent *currentEvent = [NSApp currentEvent];
>         int optionKey = [currentEvent modifierFlags] & NSAlternateKeyMask;
>         
>         if (optionKey == 0) dragOp = NSDragOperationMove; // option not 
> pressed
>         return dragOp;
>     }
>     
>     // if drag source is not self then... OUTSIDE FILE BEING DRAGGED IN
>     NSArray*firstType = [NSArrayarrayWithObjects:NSURLPboardType, nil];
>     
>     if([[[info draggingPasteboard] types] containsObject:NSURLPboardType] ) {
>         NSString *availableType = [[info draggingPasteboard] 
> availableTypeFromArray:firstType];
>         NSString *fileType;
>         NSURL *url;
>         NSArray *filesList = [[info draggingPasteboard] 
> propertyListForType:availableType];
>         
>         for (int i=0; i<[filesList count]; ++i) {
>             url = [filesList objectAtIndex:i];
>             
>             if ([url getResourceValue:&fileType forKey:NSURLTypeIdentifierKey 
> error:NULL]) {
>                 NSLog(@"%@", fileType); // just print the type for now
>             }
>         }
>     }
>     
>     [tv setDropRow:row dropOperation:NSTableViewDropAbove];    
>     return dragOp;
> }
> 
> 
> 
> So as I'm sure you've noticed, I'm not changing the dragOp for an outside 
> file being dragged in.  For some reason I keep getting an unrecognized 
> selector error with the getResourceValue:forKey:error: method.  I'm 
> completely stumped, any help would be greatly appreciated.

A few points:

* When asking for help about an error, always copy and paste the error 
verbatim.  Otherwise, you're giving incomplete information to the people of 
whom you're asking help.

* Always read the error and attempt to understand it.  In particular, an 
unrecognized selector error generally indicates the class of the instance which 
received and didn't recognize the message.  In your case, the instance will be 
of some type other than NSURL.  I know that because NSURL does recognize 
-getResourceValue:forKey:error:.  An unrecognized selector error is about a 
mismatch between the message you've sent and the class of the object to which 
you've sent it.  After verifying that you're sending the right message -- 
double checking that you did what you meant and didn't make a typo -- it's time 
to verify the identity of the receiver.

* To that end, log the value of any and all objects about which you've made 
assumptions which are under question.  In this case, you should log the object 
pointed to by "url".

* If it's not of the class that you expect, look at the method that gave it to 
you.  In particular, -[NSPasteboard propertyListForType:] is documented as 
returning property list types.  NSURL is not a property list type.  So, that's 
not the right method to use to obtain an NSURL from the pasteboard.

* Check the documentation for NSURLPboardType.  That explains how you are 
supposed to read URLs off of the pasteboard.

* Finally, what you're trying to achieve is built into the frameworks from 10.6 
forward.  See the docs for NSPasteboardURLReadingContentsConformToTypesKey.

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to