5

Consider a view (parent) with a subview (child). Both have registered for the dragged type NSFilenamesPboardType.

parent is only interested in image files and child in audio files. If they detect a file of the corresponding type in draggingEntered: they return NSDragOperationCopy. If not, they return NSDragOperationNone.

child overlaps parent and when a drag reaches child, parent receives a draggingExited: message, no matter if child is interested in the drag or not.

How can I make parent receive the drag if child does not want it?

2
  • Does the child always get draggingEntered: before the parent gets a draggingExited: in this case? (or vice-versa, always?) It's important to know if the order of events is 100% consistent. If its not 100% consistent, then that makes the solution a little more complicated.
    – MechEthan
    Jun 13, 2012 at 17:52
  • Is it possible to share a simple image/schematic showing the layout of the views?
    – Alladinian
    Jun 14, 2012 at 6:11

3 Answers 3

3
+75

If I get this right you should call:

[self.superview yourmethod];

in the childs function.

If the child inherited from the parent you can call:

[super yourmethod];
1
  • what is yourmethod? Sep 4, 2017 at 21:49
2

There are a couple of things you could do here:

  1. As @Thomas mentioned, you could implement logic in the child view to determine whether or not the drag events should be forwarded to the parent view and forward the events when appropriate.

  2. You could unregister the child view from receiving drag messages ([childView unregisterDraggedTypes]) and then you could implement all of the logic for drags in the parentView. Essentially, the idea would be to calculate the type and position of the drag and whether or not it intersects with the child view. If it does intersect with the child view, apply the drag logic for the child view. Otherwise, apply the drag logic for the parent view. You will probably need to implement draggingUpdated: to accomplish this.

1

You can consider make the parent as the only one which register for NSFilenamesPboardType.

And like the UIResponderChain, create a category for each subviews

- (NSView*) dragTest:(id< NSDraggingInfo >)sender;

if the returned value is nil, it means that the subview (and its subivews) doesn't wish to handle the drag event.

Now back to parentview, when draggingEntered: triggered, calculate the location and find out which view it is on, call dragTest: to check if the corresponding subview wish to handle it. Let the returned non-null view to handle the event, otherwise handle it in the parent.

This method will be helpful if you have many level of subviews.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.