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
.
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
Updating the menu items in NSEventTrackingRunLoopMode
solved this issue.
I am dynamically populating menu items in a timer and NSMenu is not updating while it's open.
Make sure to have the timer fire on the respective run mode:
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
You might only have it fire on NSDefaultRunLoopMode
right now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With