objective c - MacRuby can't link controller to new window xib -


my setup

  • xcode 4.3.2
  • macruby 0.12 (ruby 1.9.2) [universal-darwin10.0, x86_64]
    • latest nightly of 4 jun, 2012
  • os 10.7.3

goal

have window controls in separate xib mainmenu.xib , able open window programmatically. not want open @ launch.

attempts

  1. i made new xib (woot.xib) , created window in it
  2. i made new ruby class

    class wootcontroller < nswindowcontroller     attr_accessor :window     def windownibname          return 'woot'     end end 
  3. i tried set class of file's owner in woot.xib wootcontroller, found will not if < nswindowcontroller in class definition. if remove < nswindowcontroller class definition, outlets populate , can link window in xib window outlet in class.
  4. from inside appdelegate's applicationdidfinishlaunching method, i've tried

    attempt

    newwind = wootcontroller.new puts newwind #outputs "#<addcredentialsdialog:0x400191180>" newwind.window().makekeyandorderfront(self) # results in no method error nil 

    attempt 2

    newwind = wootcontroller.initwithwindownibname 'addwindow' puts newwind #outputs "#<addcredentialsdialog:0x400191180>" newwind.window().makekeyandorderfront(self) # results in no method error nil 

questions

  1. why don't either of attempts work? i've ready can find on macruby , using nswindowcontroller.
  2. why can't link class wootcontroller if have inheriting nswindowcontroller
  3. is there different way other putting in mainmenu.xib?

this solution works

nib = nsnib.alloc.initwithnibnamed('woot', bundle: nil) newwind = wootcontroller.new nib.instantiatenibwithowner(newwind, toplevelobjects:nil) newwind.showwindow(self) 

some things note

  1. in macruby, if there named parameters method signature, must use them if specify nil or method signatures don't match , no method error.

    ie. obj.foo('hello', to_whom: nil) not same obj.foo('hello')

  2. if there named parameters must use parentheses.

    ie. this obj.foo('hello', to_whom: nil) work, not this obj.foo 'hello', to_whom: nil


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -