我使用下拉菜單創建了一個statusBar應用程序。我想從該下拉菜單中打開一個settingsWindow。我用自己的ViewController製作了設置窗口。如何使用Swift中的AppDelegate從自己的ViewController打開一個新窗口
問題是,我無法弄清楚如何實例化並顯示我所做的settingsWindow。我試圖按照互聯網上的每一個線索,沒有任何成功。
我的ViewController:
class SettingsViewController: NSViewController {
@IBOutlet var ipAddress: NSTextField!
@IBOutlet var port: NSTextField!
@IBAction func connect(sender: AnyObject) {}
override func viewDidLoad() {
super.viewDidLoad()
}
}
我的AppDelegate:
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var statusMenu: NSMenu!
var statusItem: NSStatusItem?
var tcpService: TcpService = TcpService()
func applicationDidFinishLaunching(aNotification: NSNotification?) {
let bar = NSStatusBar.systemStatusBar()
statusItem = bar.statusItemWithLength(20)
statusItem!.menu = statusMenu
statusItem!.image = NSImage(byReferencingFile: NSBundle.mainBundle().pathForResource("16*16", ofType: "png"))
statusItem!.highlightMode = true
tcpService.initOutputStream("192.168.1.1", Port: 8888)
}
func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}
@IBAction func openSettings(sender: AnyObject) {
// open settings for ip and port optional port
}
}
爲什麼不使用模式窗口? – derdida 2014-09-25 22:56:41