質問

I need to get notified when menu items in an NSMenu instance get removed. Specifically because I'm holding a NSMenuItem *selectedItem instance in my class. If this selectedItem gets removed from my NSMenu instance, i want to set the selectedItem to nil;

There is a notification for NSMenu called "NSMenuDidRemoveItemNotification" that works when you remove individual items from the menu. But when you call [myNSMenu removeAllItems] it does not get called.

Any ideas? , Do I need to subclass NSMenu ? Thanks.

役に立ちましたか?

解決

Yes, you are right, there is no notification for removeAll.

And you rightly said you need to subclass

Or, need some tricks (may be hacky work)

Even you can make a category with a method as removeEachItem.

If the menu is left with only one item you can track that NSMenuDidRemoveItemNotification is getting called last time, you are done with your requirement.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top