How to drop a file anywhere on the window

Discussion in 'Mac Programming' started by sirjorj, Nov 16, 2008.

  1. sirjorj macrumors newbie

    Joined:
    Oct 26, 2007
    #1
    Hi. I am fairly new to Cocoa programming and I have a problem that I have not been able to figure out. I have a simple little Cocoa app consisting of a TableView and a multiline TextField and I want to be able to drop a file anywhere on the app. I have made an app that would accept drop on a textfield, but now I want to be able to drop it anywhere on the window.

    First I tried selecting the main view in Interface Builder and changing the class to DroppableView (a class I made subclassed from NSView to implement the drag/drop handlers) but initWithFrame would never fire when I run the program.

    Then I returned the class to NSView and covered it with a CustomView control and set its class to DroppableView. This would fire the initWithFrame controls, but the TableView and TextField that I had on top of the control were no longer visible.

    This shouldn't be that complicated of a thing to do, but I am out of ideas. Any help?

    jorj
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Stick with your original idea but override initWithCoder: instead.
     
  3. sirjorj thread starter macrumors newbie

    Joined:
    Oct 26, 2007
    #3
    Thanks a ton! I have been looking for that for a while!

    UPDATE: Now the view catches the events but the TableView and TextField I have on it are not visible at runtime. Do I have to programmatically add them since I overrode the view?

    ANOTHER UPDATE: never mind - I wasn't calling super's init - now it works

    jorj
     

Share This Page