Use performSelector:withObject:afterDelay:0 to push your response to the end of 
the run loop, giving the UI a chance to update first. It's what I do when a 
button (etc) is going to trigger something that won't be instantaneous, where 
the button shouldn't keep showing in the pressed state while it happens.

On May 29, 2013, at 3:41 PM, Steve Mills wrote:

> I have an NSView subclass that's used to draw contents of a menu item. When I 
> get a mouseUp in my view, I need to flash the hilite (I'm guessing just draw 
> it a couple times with a short delay between draws), dismiss the menu and 
> perform the action associated with the item. These seem like the right 
> methods to use, but the menu is not closing before the action executes. 
> What's a better way to do this? The MenuItemView sample app also has this 
> problem when you click the Button.
> 
> - (void)mouseUp:(NSEvent*)event
> {
>       UNUSED_VAR(event);
>       
>       NSMenuItem*             item = [self enclosingMenuItem];
>       NSMenu*                 menu = [item menu];
>       
>       // On mouseUp, we want to dismiss the menu being tracked:
>       [menu cancelTracking];
>       
>       // Then send the action to the target:
>       SEL                             act = [item action];
>       id                              targ = [item target];
>       
>       if(act != nil && targ != nil)
> //            [NSApp sendAction:act to:targ from:item];
> // Temporarily sending the About menu item so it'll fire the About box:
>               [NSApp sendAction:act to:targ from:[menu itemAtIndex:0]];
>       
> // Copied from MenuItemView sample project. I don't think this is necessary:
> //    [self setNeedsDisplay:YES];
> }
> 
> --
> Steve Mills
> office: 952-818-3871
> home: 952-401-6255
> cell: 612-803-6157
> 
> 
> 
> _______________________________________________
> 
> 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/lrucker%40vmware.com
> 
> This email sent to lruc...@vmware.com


_______________________________________________

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