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
- i made new xib (woot.xib) , created window in it
i made new ruby class
class wootcontroller < nswindowcontroller attr_accessor :window def windownibname return 'woot' end end- i tried set class of file's owner in woot.xib wootcontroller, found will not if
< nswindowcontrollerin class definition. if remove< nswindowcontrollerclass definition, outlets populate , can link window in xib window outlet in class. from inside appdelegate's
applicationdidfinishlaunchingmethod, i've triedattempt
newwind = wootcontroller.new puts newwind #outputs "#<addcredentialsdialog:0x400191180>" newwind.window().makekeyandorderfront(self) # results in no method error nilattempt 2
newwind = wootcontroller.initwithwindownibname 'addwindow' puts newwind #outputs "#<addcredentialsdialog:0x400191180>" newwind.window().makekeyandorderfront(self) # results in no method error nil
questions
- why don't either of attempts work? i've ready can find on macruby , using nswindowcontroller.
- why can't link class
wootcontrollerif have inheritingnswindowcontroller - 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
in macruby, if there named parameters method signature, must use them if specify nil or method signatures don't match ,
no methoderror.ie.
obj.foo('hello', to_whom: nil)not sameobj.foo('hello')if there named parameters must use parentheses.
ie. this
obj.foo('hello', to_whom: nil)work, not thisobj.foo 'hello', to_whom: nil
Comments
Post a Comment