2012-09-07 33 views
0

我在iOS上玩了一段時間後,開始使用我的第一個原生mac應用程序。通過菜單項顯示的窗口設置不正確?

我試圖從菜單項啓動一個窗口,但我懷疑我做錯了。任何IBAction我連接到這個新窗口上的按鈕會返回一個錯誤。

這是我在做什麼。從菜單項我推出這個:

-(IBAction)displaySAInput:(id)sender{ 

NSLog(@"Input selected."); 
inputSAViewController = [[NSWindowController alloc] initWithWindowNibName:@"InputViewController"]; 
[inputSAViewController showWindow:self]; 

這將啓動InputViewController筆尖是由InputViewController類擁有。我將InputViewController類設置爲從NSWindowController繼承。

InputViewController.m我已經測試IBAction S,從而爲:

-(IBAction)testButton:(id)sender{ 

NSLog(@"Data recalled?"); 

} 

我此IBAction連接到通過界面生成器的按鈕。一切看起來沒問題。

當我建立並點擊任何東西之前打開InputViewController窗口,我在控制檯收到此錯誤:

Could not connect the action testButton: to target of class NSWindowController 

我已經廣泛搜查,但我的無知,使我從連接點。此線程based on a similar error with NSApplication看起來很有希望,但我不太明白我需要什麼來使連接發生與NSWindowController錯誤相關。

這應該很簡單。我錯過了什麼?

回答

0

前手只是加載NSWindow,使其不可見,當IBAction爲被調用時,只需做到以下幾點:

[myWindow setIsVisible:YES]; 
[myWindow setLevel:NSFloatingWindowLevel]; 

耶!

+0

只是爲了確保我明白了,你說我應該讓它成爲菜單本身的文件所有者下,而不是從一個新的類推出呢?那麼只需切換其可見性? –

+0

是的,至少這是我所做的,它完美的作品。 – David

+0

我最終走上了這條路。非常感謝! –

1

您的代碼:

-(IBAction)displaySAInput:(id)sender{ 
    NSLog(@"Input selected."); 
    inputSAViewController = [[NSWindowController alloc] 
        initWithWindowNibName:@"InputViewController"]; 
    [inputSAViewController showWindow:self]; 
} 

通知你分配/ INITING的NSWindowController,不是你的自定義子類,你已經實現了testButton:方法的通用實例。我以爲你很可能希望出現這種情況變爲:

-(IBAction)displaySAInput:(id)sender{ 
    NSLog(@"Input selected."); 
    inputSAViewController = [[InputViewController alloc] 
        initWithWindowNibName:@"InputViewController"]; 
    [inputSAViewController showWindow:self]; 
} 
+0

這聽起來很有希望......首次嘗試時出現鏈接錯誤。努力解決。 –

+0

這是我仍然收到的錯誤...體系結構x86_64的未定義符號:「_OBJC_CLASS _ $ _ InputViewController」,引用自:ReportController.old中的objc-class-ref:未找到體系結構x86_64的符號clang:錯誤:鏈接器命令失敗,退出代碼1(使用-v查看調用) –

+0

已解決的鏈接器問題(ReportController.m未在目標編譯列表中列出),但在更新到建議後仍然收到錯誤:無法連接操作testButton:到類InputViewController的目標 –