Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:02:37+00:00 2026-06-03T01:02:37+00:00

I’m trying to implement drag and drop from the Finder into an NSTableView of

  • 0

I’m trying to implement drag and drop from the Finder into an NSTableView of my app. The setup uses an NSTableView, an array controller which acts as a datasource using Cocoa bindings to a Core Data store.

I did the following, basically following various blog posts I found on SO and other sites:

In the awakeFromNib of my view controller I call:

[[self sourcesTableView] registerForDraggedTypes:[NSArray arrayWithObjects: NSPasteboardTypePNG, nil]];

I subclassed NSArrayController and added the following methods to my subclass (the reasoning for subclassing is that the array controller needs to be informed of the drop as it acts as the datasource of the table view):

- (BOOL) tableView: (NSTableView *) aTableView acceptDrop: (id < NSDraggingInfo >) info row: (NSInteger) row dropOperation: (NSTableViewDropOperation)operation

My implementation for the above currently only writes to the log and then returns a boolean YES.

- (NSDragOperation) tableView: (NSTableView *) aTableView validateDrop: (id < NSDraggingInfo >) info proposedRow: (NSInteger) row proposedDropOperation: (NSTableViewDropOperation) operation

In IB I have the array controller pointing to my custom NSArrayController subclass.

Result: nothing. When I drag a PNG from the desktop onto my table view, nothing happens and the file happily bounces back to its origin. I must be doing something wrong but don’t understand what. Where am I going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:02:39+00:00Added an answer on June 3, 2026 at 1:02 am

    A drag from the Finder is always a file drag, not an image drag. You’ll need to support the dragging of URLs from the Finder.

    To do that, you need to declare that you want URL types:

    [[self sourcesTableView] registerForDraggedTypes:[NSArray arrayWithObject:(NSString*)kUTTypeFileURL]];
    

    You can validate the files like so:

     - (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
    {
        //get the file URLs from the pasteboard
        NSPasteboard* pb = info.draggingPasteboard;
    
        //list the file type UTIs we want to accept
        NSArray* acceptedTypes = [NSArray arrayWithObject:(NSString*)kUTTypeImage];
    
        NSArray* urls = [pb readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]]
         options:[NSDictionary dictionaryWithObjectsAndKeys:
                    [NSNumber numberWithBool:YES],NSPasteboardURLReadingFileURLsOnlyKey,
                    acceptedTypes, NSPasteboardURLReadingContentsConformToTypesKey,
                    nil]];
    
        //only allow drag if there is exactly one file
        if(urls.count != 1)
            return NSDragOperationNone;
    
        return NSDragOperationCopy;
    }
    

    You’ll then need to extract the URL again when the tableView:acceptDrop:row:dropOperation: method is called, create an image from the URL and then do something with that image.

    Even though you are using Cocoa bindings, you still need to assign and implement an object as the datasource of your NSTableView if you want to use the dragging methods. Subclassing NSTableView will do no good because the datasource methods are not implemented in NSTableView.

    You only need to implement the dragging-related methods in your datasource object, not the ones that provide table data as you’re using bindings to do that. It’s your responsibility to notify the array controller of the result of the drop, either by calling one of the NSArrayController methods such as insertObject:atArrangedObjectIndex: or by modifying the backing array using Key-Value Coding-compliant accessor methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.