Re: Updating NSMenu while it's open
Re: Updating NSMenu while it's open
- Subject: Re: Updating NSMenu while it's open
- From: Dave DeLong <email@hidden>
- Date: Wed, 18 Apr 2012 18:54:14 -0700
Nothing nearly so complicated. You just have to realize that the runloop is in a different mode while the menu is open. If you have a timer to periodically update your menu, then you have to add the timer to the runloop under the NSEventTrackingRunLoopMode. From there, add or update whatever NSMenuItems you want, and then call -[NSMenu update].
More info: http://stackoverflow.com/q/2808016/115730
Dave
Sent from Jane
On Apr 18, 2012, at 6:47 PM, Graham Cox <email@hidden> wrote:
>
> On 19/04/2012, at 10:04 AM, Jerry Krinock wrote:
>
>>
>> On 2012 Apr 18, at 13:14, vinayak pai wrote:
>>
>>> I have a NSMenu with dynamically added NSMenuItems. The NSMenu is not refreshing properly while it's kept open.
>>
>> I do not believe there is any way to refresh a menu while it is open. The method in which you do your dynamism, -menuNeedsUpdate, is only guaranteed to be invoked when the user clicks the menu. Although I've seen it invoked at other times, this seems to be some kind of performance optimization.
>>
>> You must redesign your app to not require refreshing a menu while it is open.
>
>
> Not true - the system's WiFi menu updates while it is open.
>
> Perhaps you need to use a view-based menu item to achieve this? You can use NSMenuItem's -setView: method to attach a view to the item, then (I assume, I haven't done it myself) you can use the usual -setNeedsDisplay on that view to update it as necessary.
>
> --Graham
>
>
>
> _______________________________________________
>
> 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