• 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: drag & drop objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drag & drop objects


  • Subject: Re: drag & drop objects
  • From: Ken Tozier <email@hidden>
  • Date: Tue, 3 Jul 2007 10:16:02 -0400


On Jul 3, 2007, at 10:06 AM, Joe Wildish wrote:

Hi Ken,

If I'm doing drag-and-drop within the same application, I often have some kind of instance variable somewhere that stores reference to the item being dragged. Once the drag is complete, I have the method query the instance variable, rather than the pasteboard. That way I can avoid the pasteboard all together.

How do you avoid the pasteboard? The "dragImage:at:offset:event:pasteboard:source:slideBack:" method requires a pasteboard. Do you just create a dummy one and ignore it? I would think that, at the very least, the drag target would need to know what type of data is being dropped so it highlights correctly and can decide to handle the drop or not...



Of course, it depends on the complexity of your dragging - it may be your source and destination can cater for many different kinds of objects being dragged, in which case you'd need to be a bit cleverer than simply using a single reference. I'm sure the approach would still work however.


Regards,
-Joe

On 3 Jul 2007, at 14:58, Ken Tozier wrote:

Hi

I'm taking my first serious foray into drag & drop and was wondering how to drag objects from one view to another. NSPasteboard doesn't seem to support arbitrary objects with any of its set data methods. I tried doing the following but it did something bad to the system necessitating a hard reboot.

NSPasteboard *pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
NSString *classPBoardType = [NSStringFromClass(self class]) stringByAppendingString: @"PBoardType"];


NSLog(@"pboard: %@, declaring pboard types", pboard);
[pboard declareTypes: [NSArray arrayWithObject: classPBoardType] owner: self];


NSLog(@"adding drag data: %@ to pboard", dd);
[pboard setData: self forType: classPBoardType]; // <- this is what messed up the system


I'm guessing that I'll have to write an encodeWithCoder/ decodeWithCoder for custom objects and use [NSKeyedArchiver archivedDataWithRootObject: self], but I'm not sure if there is a better way to do this.

Is it necessary to archive objects for drags between two views in the same window? If not, how do you put such objects on the pasteboard and how do you define their type?

Thanks for any help

Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
40comcast.net


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: drag & drop objects
      • From: Jerry Krinock <email@hidden>
    • Re: drag & drop objects
      • From: Joe Wildish <email@hidden>
References: 
 >drag & drop objects (From: Ken Tozier <email@hidden>)
 >Re: drag & drop objects (From: Joe Wildish <email@hidden>)

  • Prev by Date: Re: NSButtonCell mouseEntered/mouseExited stops after view is swapped out ...
  • Next by Date: outdated link in Cocoa documentation
  • Previous by thread: Re: drag & drop objects
  • Next by thread: Re: drag & drop objects
  • Index(es):
    • Date
    • Thread