Professional Web Applications Themes

Dragging into NSTableView subclass - Mac Programming

Hello, I want to support dragging pictures into a a TableView, but I an't make it work. I'm certain that this is just because I am such a Cocoa newbie, but I was hoping that has done this could help me. According to the doentation on NSTableView, NSTableView already implements drag and drop, so instead of implementing the three methods you normally implement, you implement : - (NSDragOperation)tableView: (NSTableView *)tableView validateDrop: (id <NSDraggingInfo>)info proposedRow: (int)row proposedDropOperation: (NSTableViewDropOperation)operation and - (BOOL)tableView :(NSTableView *)tableView acceptDrop :(id <NSDraggingInfo>)info row :(int)row dropOperation: (NSTableViewDropOperation)operation Here's what I have in my implementation file now, and I've ...

  1. #1

    Default Dragging into NSTableView subclass

    Hello,

    I want to support dragging pictures into a a TableView, but I an't make
    it work. I'm certain that this is just because I am such a Cocoa newbie,
    but I was hoping that has done this could help me.

    According to the doentation on NSTableView, NSTableView already
    implements drag and drop, so instead of implementing the three methods
    you normally implement, you implement :

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

    and

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

    Here's what I have in my implementation file now, and I've set break
    points on both return statements.

    #import "imageTableView.h"

    implementation imageTableView
    - (id)initWithCoder:(NSCoder *)coder
    {
    /*------------------------------------------------------
    Init method called for Interface Builder objects
    --------------------------------------------------------*/
    if(self=[super initWithCoder:coder]){
    //register for all the image types we can display
    [self registerForDraggedTypes:[NSImage imagePasteboardTypes]];
    }
    return self;
    }
    - (NSDragOperation)tableView:
    (NSTableView *)tableView validateDrop:
    (id <NSDraggingInfo>)info proposedRow:
    (int)row proposedDropOperation:
    (NSTableViewDropOperation)operation
    {
    return NSDragOperationCopy;
    }

    - (BOOL)tableView
    :(NSTableView *)tableView acceptDrop
    :(id <NSDraggingInfo>)info row
    :(int)row dropOperation:
    (NSTableViewDropOperation)operation
    {
    return true;
    }
    end

    When I run my app under the xcode debugger, it doesn't seem that
    proposedDropOperation or dropOperation ever get called. The only think
    that I can think of now is that perhaps the NSScrollView gets the drag,
    and that I have to pass it through to the tableview somehow.

    PS: I downloaded Apple's Drag and Drop sample, and it works fine, but
    they don't derive from TableView, they derive from ImageView.

    TIA.

    Cheers, Rick
    Rick Guest

  2. #2

    Default Re: Dragging into NSTableView subclass

    In article <attbi.com>,
    Rick Spencer <com> wrote:
     

    The doentation states those named methods are called on the table's
    data source, not on the table (or your subclass) itself, which is what
    it appeared you implemented.
    Doc Guest

  3. #3

    Default Re: Dragging into NSTableView subclass

    In article <supernews.com>,
    Doc O'Leary <com> wrote:
     
    >
    > The doentation states those named methods are called on the table's
    > data source, not on the table (or your subclass) itself, which is what
    > it appeared you implemented.[/ref]

    Thank you. I got some sample code, and it took me about an hour to
    figure out that associating the datasource to the tableview is done in
    interface builder! I think I'll be able to piece it together now. Cocoa
    still seems like very strange environment to me.

    The sample code I'm looking at is called TableTester. I found it one
    Google. Here's the URL in case any other newbies read this thread:

    http://www.karelia.com/tabletester/

    Cheers, Rick
    Rick Guest

  4. #4

    Default Re: Dragging into NSTableView subclass

    Rick Spencer <com> wrote:
     

    It doesn't have to be. m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    AppleScript: The Definitive Guide
    http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

Similar Threads

  1. NSTableView with preselected rows display problem
    By rick in forum Mac Programming
    Replies: 3
    Last Post: December 4th, 11:56 PM
  2. Sorting NSTableView contents
    By C in forum Mac Programming
    Replies: 5
    Last Post: November 15th, 03:18 PM
  3. Navigating in NSTableView
    By Loic in forum Mac Programming
    Replies: 3
    Last Post: October 23rd, 12:23 AM
  4. help w/ multiple columns in NSTableView
    By Willian Irving Zumwalt in forum Mac Programming
    Replies: 2
    Last Post: September 23rd, 03:05 AM
  5. [Cocoa] Bug with NSTableView?
    By Mark Bee in forum Mac Programming
    Replies: 1
    Last Post: July 7th, 07:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139