如何防止故事板打开一个窗口 [英] how to prevent storyboard from opening a window

查看:163
本文介绍了如何防止故事板打开一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个简单的应用程序加载到状态栏,当点击它打开状态栏图标下的popover。我使用storyboards来定义我喜欢在我的popover显示的UI。事情是一旦我实例化故事板一个窗口打开。如何防止这种情况?这是我的应用程序委托中的代码:

  func applicationDidFinishLaunching(aNotification:NSNotification){
let mainBoard = NSStoryboard name:MainBoard,bundle:nil)
}


解决方案>

  import Cocoa 

@NSApplicationMain
class AppDelegate:NSObject,NSApplicationDelegate {
var defaultWindow:NSWindow!
func applicationDidFinishLaunching(aNotification:NSNotification){
defaultWindow = NSApplication.sharedApplication()。windows.first as? NSWindow
defaultWindow.close()

}
func applicationWillTerminate(aNotification:NSNotification){
//在此插入代码以删除应用程序
}
@IBAction func menuClick(sender:AnyObject){
defaultWindow.makeKeyAndOrderFront(nil)
}
}

更新: Xcode 7.1.1•Swift 2.1

  NSApplication.sharedApplication()。windows.first?.close()


I am writing a simple application that loads into the status bar and when clicked it opens a popover under the status bar icon. I am using storyboards to define the UI I like to show in my popover. The thing is as soon as I instantiate the storyboard a window opens up. How can I prevent that? This is the code in my application delegate:

func applicationDidFinishLaunching(aNotification: NSNotification) {
    let mainBoard = NSStoryboard(name: "MainBoard", bundle: nil)
}

解决方案

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    var defaultWindow:NSWindow!
    func applicationDidFinishLaunching(aNotification: NSNotification) {
        defaultWindow = NSApplication.sharedApplication().windows.first as? NSWindow
        defaultWindow.close()

    }
    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
    @IBAction func menuClick(sender: AnyObject) {
        defaultWindow.makeKeyAndOrderFront(nil)
    }
}

update: Xcode 7.1.1 • Swift 2.1

NSApplication.sharedApplication().windows.first?.close()

这篇关于如何防止故事板打开一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆