NSMenu打开时如何更新? [英] How to update NSMenu while it's open?

查看:243
本文介绍了NSMenu打开时如何更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有动态添加的NSMenuItems的NSMenu.保持打开状态时,NSMenu无法正确刷新.我在NSEventTrackingRunLoopModes中调用NSMenu更新方法.

I have a NSMenu with dynamically added NSMenuItems. The NSMenu is not refreshing properly while it's kept open. I am calling NSMenu update method in NSEventTrackingRunLoopModes.

我已经实现了以下方法来更新NSMenu.

I have implemented following methods to update NSMenu.

- (void)menuNeedsUpdate:(NSMenu *)menu {
for (NSInteger index = 0; index < count; index++)
    [self menu:menu updateItem:[menu itemAtIndex:index] 
                       atIndex:index 
                  shouldCancel:NO];
}

- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel`

- (NSInteger)numberOfItemsInMenu:(NSMenu *)menu

推荐答案

更新NSEventTrackingRunLoopMode中的菜单项解决了此问题.

Updating the menu items in NSEventTrackingRunLoopMode solved this issue.

这篇关于NSMenu打开时如何更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆