【发布时间】:2014-09-25 20:42:08
【问题描述】:
我创建了一个带有下拉菜单的状态栏应用程序。我想从该下拉列表中打开一个设置窗口。我已经用自己的 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
}
}
【问题讨论】:
-
为什么不使用模式窗口?
标签: macos cocoa swift nswindow nsviewcontroller