6

I have a controller object that owns an NSMenu and is that menu's delegate, in the interest of lazy population.

However, neither numberOfItemsInMenu: nor menuNeedsUpdate: is ever called, and so the menu remains empty.

I have confirmed that:

  • The controller object has not been deallocated. (The controller, in turn, owns the menu.)
  • It does have a menu.
  • The menu does have a delegate, and that is the controller.

If I implement menuWillOpen:, that is called, but you're not supposed to populate the menu there.

I tried sending the menu an update message, and that had no effect. The delegate remained un-called, and the menu remained empty.

In case it's relevant: This menu is not in the main menu; it is used elsewhere.

Why isn't the menu asking its delegate to populate it? Is there something I've missed, or is this just broken?

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • Can you paste your code here. So that we will also try it out? – Hussain Shabbir Dec 21 '13 at 05:14
  • @hussainShabbir: Nope. The code doesn't belong to me; I was working on a contract job. (Besides which, I already changed it to not rely on those methods being called by the system.) – Peter Hosey Dec 21 '13 at 07:37
  • I am having exactly same issue now, and your mention about `menuWillOpen:` saved my time a lot. For the record, `menuDidClose:` also makes same issue even for setting `enabled` property of a menu item. The only thing that working is `menuNeedsUpdate:`. – eonil Nov 15 '15 at 03:10

1 Answers1

0

Maybe you need a strong reference to the delegate. Try moving variable declaration out of your method and make a class-level member variable. look at this answer: https://stackoverflow.com/a/21816149/1664943

Community
  • 1
  • 1
ThorstenC
  • 1,264
  • 11
  • 26
  • You missed this part of the question: “I have confirmed that: • The controller object has not been deallocated.” – Peter Hosey Feb 16 '14 at 22:40
  • Did you have at one point a View setMenu:.. ? If yes- where do you have the Menu variable decelerated? In my case the controller also was NOT deallocated, but ARC has invalidated the reference to my delegate. – ThorstenC Feb 17 '14 at 00:02
  • The controller object I was referring to is the menu's delegate and its owner. – Peter Hosey Feb 17 '14 at 02:13