views:

42

answers:

2

Hi,

I'm implementing a custom status bar menu, which has a custom view with NSSearchField. I'm updating number of menu items according to search results. The number of menu items is changed as user types in the NSSearchField. I've noticed, that if number of results stays the same, items titles are not updated (redrawn). How do I force them to redraw?

In the function, that rebuilds the menu I remove first all items and then create new items according to the search results.

Thanks,

Nava

A: 

on the menu set menuChangedMessagesEnabled to YES when you want to update the menu:

[menu setMenuChangedMessagesEnabled:NO];
// change the menu
[menu setMenuChangedMessagesEnabled:YES];

The second invocation causes the menu to apply changes. The first one is so that you can batch a group of changes together.

That said, Apple guidelines discourages changing menus while they're open as users are not used to this and can be confusing. If it's feasible try to redesign your app so you can use something else, say a table or matrix, instead of a menu.

Mo
That's what the documentation says:/* In SnowLeopard, the following methods no longer do anything useful. */- (void)setMenuChangedMessagesEnabled:(BOOL)flag;:(Is there some other way to do it?
Nava Carmon
hmm, so it seems. Have you tried calling `itemChanged:`? I'm not sure if this is the intended use for it, but might work.
Mo
yes, i tried, doesn't help
Nava Carmon
A: 

I could achieve it by following approach: When the number of search results is the same, i don't recreate them, just change the title and call itemChanged:. When the count is different I recreate menu items. This works anyway. But I was advised anyway to get back from using menu for this purposes.

Nava Carmon