2015-09-30 64 views
0

我讀「Cocoa編程爲OS X」(大Neard牧場GUID)和我進行了一個簡單的應用程序來測試與窗控制器與廈門國際銀行文件的空窗應用這個控制器。我已經根據這本書編寫了所有必要的代碼,但是在構建應用程序並關閉應用程序窗口之後,我無法重新打開應用程序的窗口。哪裏不對 ?在代碼下面。 (I在MainMenu.xib刪除窗口和相應改變的AppDelegate;和在可見發射框未選中) )。這本書說showWindow(_ :)將重新打開窗口,但我沒有看到這個!如何重新打開應用程序的窗口時,Xcode

import Cocoa 

@NSApplicationMain 
class AppDelegate: NSObject, NSApplicationDelegate { 

var control: Control? 

func applicationDidFinishLaunching(aNotification: NSNotification) { 

    //Create a window controller object 
    let control = Control() 

    //Put the window of the window controler om the screen 
    control.showWindow(self) 

    //Set the propertity to point to window controler 
    self.control = control 

} 


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


} 
在我的控制器類

import Cocoa 
class Control: NSWindowController 
{ 
    override var windowNibName: String? 
     { 
      return "Control" 
} 
} 

在文件所有者身份

是控制控制器和窗口已連接到窗口的出口。

回答

1

您必須添加以下申請的委託方法。

func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { 
    if flag { 
     control.window.orderFront(self) 
    } else { 
     control.window.makeKeyAndOrderFront(self) 
    } 
    return true 
} 
+0

非常感謝!!!!這應該在書中。 – VYT

+0

@Cory是有可能這個代碼轉換成由一個Xcode AppleScript的應用程序的東西可讀?我有這個問題,每當我關閉應用程序的窗口,它仍然在運行,但不能通過點擊停靠點圖標重新打開例如。我總是需要退出並重新打開它。你可以幫幫我嗎?謝謝。 – ProGrammer

相關問題