I have a window with many (up to around 80) views which can be targets of drag and drop (they can also be sources, but that doesn't appear to be relevant). Each has a suitable tracking area. I respond to drag enter and drag exit, and then to drag operation. The basics of the code is below.

- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender
{
    self.dragHighlight = YES;
    [self setNeedsDisplay:YES];
    return NSDragOperationGeneric;
}

- (void)draggingExited:(id<NSDraggingInfo>)sender
{
    self.dragHighlight = NO;
    [self setNeedsDisplay:YES];
}

- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender
{
    self.dragHighlight = NO;
    NSPasteboard *pboard = [sender draggingPasteboard];
    NSArray *classArray = @[[NSString class]];
    NSDictionary *dictionary = @{};
NSArray *draggedItems = [pboard readObjectsForClasses:classArray options:dictionary];
    if (draggedItems != nil && [draggedItems count] > 0) {
// Handle the drag, which will ensure that setNeedsDisplay is set...
        return YES;
    }
    [self setNeedsDisplay:YES];
    return NO;
}

Everything works correctly except for the drag highlight. Sometimes, and I haven't been able to work out what the sequence is, the drag highlight will be left on after the drop happens. The problem seems to be some sort of race condition, but I'm finding it hard to track down. Putting logging in each of the three methods makes the problem go away, so that isn't useful.

Am I doing something wrong? I'm on OS X 10.10.4, Xcode 6.4.

John
--
John Brownie, john_brow...@sil.org or j.brow...@sil.org.pg
Summer Institute of Linguistics      | Mussau-Emira language, Mussau Is.
Ukarumpa, Eastern Highlands Province | New Ireland Province
Papua New Guinea                     | Papua New Guinea
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to