• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Delegate methods for NSImageView (?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delegate methods for NSImageView (?)


  • Subject: Re: Delegate methods for NSImageView (?)
  • From: Bill Garrison <email@hidden>
  • Date: Fri, 6 Dec 2002 22:10:00 -0500

On Friday, December 6, 2002, at 07:08 PM, email@hidden wrote:

I need to popup a warning message to user's when certain types of images are dropped into an NSImageView (via drag & drop)... or, possibly, just prevent the drop at all if the image type is not one I intend to support. I was at first expecting there would be a simple delegate method or NSNotification for the drop event which would provide my controller a chance to manage this. However, looking at the documentation, I see no such methods/notifications. I'm sure I'm missing something obvious... what's the best way to handle this?


Eric,

The way I did this was to subclass NSImageView. In the subclass, I implemented the methods I needed from the DragDestination informal protocol, mainly -draggingEntered:, -draggingExited:, and -performDragOperation:[

<http://developer.apple.com/techpubs/macosx/Cocoa/Reference/ ApplicationKit/ObjC_classic/Protocols/NSDraggingDestination.html>

In my draggingEntered: implementation, I filter dropped URLs (I'm accepting drags from the Finder) by file extension. If the URL doesn't have the right file extension, I don't handle it. From draggingEntered:, you return the contant NSDragOperationNone to indicate that your object won't accept a the drag.

I just followed the discussion in AB&Y's "Cocoa Programming" and adding drag & drop to my image view subclass was a piece of cake. Hillegass' "Cocoa Programming for Mac OS X" has a good chapter on drag and drop, too.

Bill

PS. An alternative approach would be to treat the NSImageView as a button. Since NSImageView inherits from NSControl, it can have an action method designated to it. When you drop an image on an NSImageView instance, an action is fired off, messaging a method that you specify as the NSImageView's target. I believe that by taking this approach, you sacrifice some level of control over the whole drag&drop operation, but your needs might be satisfied just the same. I haven't tried the approach myself, so I can't say from experience.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Delegate methods for NSImageView (?) (From: email@hidden)

  • Prev by Date: How to run prefPane from Project Builder/gdb
  • Next by Date: id vs cast
  • Previous by thread: Delegate methods for NSImageView (?)
  • Next by thread: How to run prefPane from Project Builder/gdb
  • Index(es):
    • Date
    • Thread