Re: drag & drop objects
Re: drag & drop objects
- Subject: Re: drag & drop objects
- From: Joe Wildish <email@hidden>
- Date: Tue, 3 Jul 2007 15:06:55 +0100
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.
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:
This email sent to email@hidden