[MacRuby-devel] error calling target of menu item

Karl Varga kjvarga at gmail.com
Mon May 18 06:25:14 PDT 2009


In the meantime to get around the thread problem I emailed about, I
though I would add an NSMenuItem to the menu so that the user can
click an 'Update Now' button and update the data on demand.

However, whenever any of my menuitems are clicked I get the same error:

/Users/karl/projects/gigameter/GigaMeter/build/Debug/GigaMeter.app/Contents/Resources/rb_main.rb:22:in
`NSApplicationMain': wrong number of arguments (0 for 1)
(ArgumentError)
	from /Users/karl/projects/gigameter/GigaMeter/build/Debug/GigaMeter.app/Contents/Resources/rb_main.rb:22:in
`<main>'

This is how my 'Update Now' menu items is declared (here *target* is a
reference to the Controller instance):
self.updateNow =
self.menu.addItemWithTitle_action_keyEquivalent_('Update Now',
'actionUpdateNow', 'u')
self.updateNow.enabled = true
self.updateNow.target = target
self.updateNow.toolTip = 'Update your Usage Data'

and my Controller class has:

class Controller
  attr_accessor :actionQuit, :actionConfigure, :actionUpdateNow

  def actionUpdateNow(sender)
    puts "action update called\n"
    doLogin
    saveDataToDisk
    self.menu.update(self.user)
  end
 ...

end

The menu is added to an NSStatusBar as so:

    menuZone = NSMenu.menuZone
    self.menu = NSMenu.allocWithZone(menuZone).init
    self.statusBar =
NSStatusBar.systemStatusBar.statusItemWithLength(NSVariableStatusItemLength)
    self.statusBar.menu = self.menu

Any ideas what's going on here?

-- 
Karl Varga
kjvarga at gmail.com
Cell: +61 (0)4 2075 1356


More information about the MacRuby-devel mailing list