swift - How to reopen the window of app, Xcode -
i reading "cocoa programming os x" (the big neard ranch guid) , have made simplest application test empty windows app window controller , xib file controller. have wrote necessary code according book after building app , closing window of app cannot reopen window of app. wrong ? below code. (i deleted window in mainmenu.xib , accordingly changed appdelegate; , visible @ launch box unchecked) ). book says showwindow(_:) reopen window, don't see !
import cocoa @nsapplicationmain class appdelegate: nsobject, nsapplicationdelegate { var control: control? func applicationdidfinishlaunching(anotification: nsnotification) { //create window controller object let control = control() //put window of window controler om screen control.showwindow(self) //set propertity point window controler self.control = control } func applicationwillterminate(anotification: nsnotification) { // insert code here tear down application } } in controller class
import cocoa class control: nswindowcontroller { override var windownibname: string? { return "control" } } in file's owner identity control controller , window has been connected window outlet.
you have add following application delegate method.
func applicationshouldhandlereopen(sender: nsapplication, hasvisiblewindows flag: bool) -> bool { if flag { control.window.orderfront(self) } else { control.window.makekeyandorderfront(self) } return true }
Comments
Post a Comment