2017-02-26 44 views
3

applicationDidFinishLaunching當我運行我的應用程序不會被調用。的applicationDidFinishLaunching不叫,用故事板和swift3

這是我AppDelegate類的代碼:

@NSApplicationMain 
class AppDelegate: NSObject, NSApplicationDelegate { 

    let statusItem = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength) 

    func applicationDidFinishLaunching(_ aNotification: Notification) { 
     // Insert code here to initialize your application 
    } 

    func applicationWillTerminate(_ aNotification: Notification) { 
     // Insert code here to tear down your application 
    } 


} 

我使用斯威夫特3故事板我的應用程序。

答案applicationDidFinishLaunching - not triggering建議對AppDelegate.swift連接到應用程序對象的故事板。我沒有任何應用程序對象。

我的應用程序沒有主菜單,它是代理,因爲我試圖構建類似於聚光燈的東西。

我應該怎麼做才能applicationDidFinishLaunching運行?

回答

5

即使你的應用程序正在運行作爲你的故事板應該具有這種結構的代理:

enter image description here

如果沒有,拖動藍色立方體(對象)到應用場景,設置類的將對象轉到AppDelegate並將控件從Application拖動到App Delegate並選擇delegate

如果你甚至有沒有應用場景,創建故事板新項目啓動,刪除當前文件Main.storyboard並拖動新創建的項目的Main.storyboard到當前項目。

+0

謝謝!我真的錯過了應用程序場景。 –