2011-10-14 38 views
2

我想創建一個非菜單式的狀態欄應用程序。同FaceTab爲Facebook(我的意思是隻接口,而不是功能性的)......這是我的代碼:將customView添加到NSStatusItem

-(void)awakeFromNib{ 
    statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; 
    [statusItem setView:customView]; 
    //[statusItem setMenu:menu]; 
    [statusItem setTitle:@"Status"]; 
    [statusItem setHighlightMode:YES]; 
} 

..... 所以一旦我使用NSMenu一切工作正常,但是當我使用的NSView和CustomView出口沒有出現在菜單欄上。幫助PLZ!

+0

你確定customView繪製了一些東西嗎? – Rengers

回答

3

有幾個移動部件參與,所以我可以給的最好的建議是看看這個來自Vadim Shpakovski的優秀example project

+0

你可以建議我一個更簡單的方法,我只想鏈接一個自定義視圖,並使其出現,一旦我點擊我的狀態欄上的應用程序圖標。 – Behnam

+0

您無法將視圖附加到狀態項 - 您必須將NSMenu附加到它,然後將自定義視圖添加到該菜單中的NSMenuItem。不過,如果你想做任何事件處理,你會遇到各種各樣的問題。我強烈建議你使用正確的NSWindow,就像我鏈接到的示例一樣。 –

+0

是的,這就是我想要的,謝謝:),對於那些誰同樣的問題: 你只需要右鍵單擊NSMenu中的任何項目(在.xib文件中),然後將「視圖」鏈接到您的控件(如自定義查看或按鈕或其他任何東西)。 – Behnam

0

在awakeFromNib方法結束時,您可能需要在statusItem上調用retain以使其不超出作用域。我一直在努力解決這個問題,並且增加[statusItem retain];修復了這個問題,以便我現在可以在Mac OS狀態欄中看到我的狀態菜單。

-(void)awakeFromNib{ 
    statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; 
    [statusItem setView:customView]; 

    // in my code, this is uncommented, and menu is an instance variable. 
    //[statusItem setMenu:menu]; 

    [statusItem setTitle:@"Status"]; 
    [statusItem setHighlightMode:YES]; 

    // this was needed to get the icon to display in the status bar. 
    [statusItem retain]; 
}