Calling the setTitle method on an NSMenuItem object is not changing the displayed title, but is changing the property
Using MacRuby with XCode, I would like to be able to change the title of an item in my application's menu.
In my simplified example I have window with a button and a label, and a menu with a menu item in it.
I created the following class and linked @my_label to the label, @my_menu to the menu item, and the button click to the button_clicked method. When you click on the button, the text开发者_如何学JAVA of the label update to show "Someone pushed the button", but the actual displayed title of the menu is not changing.
class MyWindowController < NSWindowController
attr_accessor :my_label
attr_accessor :my_menu
def button_clicked(sender)
@my_menu.setTitle("Someone pushed the button")
@my_label.stringValue = @my_menu.title
end
end
This would seem to indicate that the title
property is being updated, but the change just isn't being shown.
I've looked at the docs for NSMenuItem and I can't see anything obvious that I'm doing wrong. However I'm pretty new to this so hopefully I'm just missing something simple.
I'm using MacRuby 0.10 with XCode 4 if that makes any difference.
Paul
that's weird. I put label and button on a window, linked them, and put a menu item on the "View" menu on top, and linked it. everything works fine. Do you have a different setup? maybe a status bar menu?
Do you have your controller as an object on the left of the grid on the xib view? (I gues you do, since you linked everything, but still..)
maybe the menu item is linked somewhere else as well?
Menu items update automatically, so this should work fine.. just check the connections again. I can send you the project I made to try it, although I doubt it will help..
精彩评论