2012-06-05 18 views
0

我設置的MacRuby不能鏈接控制器來新窗口XIB

  • 的XCode 4.3.2
  • MacRuby的0.12(紅寶石1.9.2)[萬向darwin10.0,x86_64的]
    • 最新夜間作爲6月4日的,2012
  • OS 10.7.3

目標

具有從MainMenu.xib一個單獨的廈門國際銀行與某些控件窗口,然後可以以編程方式打開該窗口。我不希望它在發佈時打開。

嘗試

  1. 我做了一個新的廈門國際銀行(Woot.xib),並在其創建的窗口
  2. 我做了一個新的Ruby類

    class WootController < NSWindowController 
        attr_accessor :window 
        def windowNibName 
         return 'Woot' 
        end 
    end 
    
  3. 我試圖設置Woot.xib中的文件所有者類爲WootController,但發現它不會如果< NSWindowController在我的類定義中。如果我從類定義中刪除< NSWindowController,那麼插座將填充,我可以將XIB中的窗口鏈接到我班的窗口。
  4. 從我的AppDelegate的applicationDidFinishLaunching方法裏面,我已經試過

    嘗試

    newWind = WootController.new 
    puts newWind #outputs "#<AddCredentialsDialog:0x400191180>" 
    newWind.window().makeKeyAndOrderFront(self) # results in no method error for nil 
    

    嘗試2

    newWind = WootController.initWithWindowNibName 'AddWindow' 
    puts newWind #outputs "#<AddCredentialsDialog:0x400191180>" 
    newWind.window().makeKeyAndOrderFront(self) # results in no method error for nil 
    

問題

  1. 爲什麼我的任何一次嘗試都不工作?我準備好了關於macruby和使用NSWindowController的所有內容。
  2. 爲什麼我不能鏈接到我的WootController類,如果我把它從NSWindowController
  3. 繼承是否有不同的方式來做到這一點除了把它全部MainMenu.xib

回答

1

此解決方案

nib = NSNib.alloc.initWithNibNamed('Woot', bundle: nil) 
newWind = WootController.new 
nib.instantiateNibWithOwner(newWind, topLevelObjects:nil) 
newWind.showWindow(self) 

需要注意以下幾點

  1. 在MacRuby的,如果有一個名爲參數的方法簽名,你必須使用他們,即使你只是指定零或方法簽名不匹配,你會得到一個no method錯誤。

    即。 obj.foo('hello', to_whom: nil)是不一樣的obj.foo('hello')

  2. 如果是命名參數,你必須使用括號。

    即。 obj.foo('hello', to_whom: nil)將工作,不是這個obj.foo 'hello', to_whom: nil

相關問題