[英]Start a main window using swift
I'm kind of new in swift, but I'm ' stuck ' in something.我是 swift 的新手,但我“卡在”某事上。
I know C, Java, C++, PHP, etc...我知道 C、Java、C++、PHP 等...
I'm trying to compose an multi-windowed App (Mac OS application using Cocoa), using swift.我正在尝试使用 swift 编写一个多窗口应用程序(使用 Cocoa 的 Mac OS 应用程序)。 I can already do it, but my problem is when I close the main window.
我已经可以做到了,但我的问题是当我关闭主窗口时。 If I close my main window, when I try to add a child to it, I will get an error or the new window just does not open.
如果我关闭我的主窗口,当我尝试向它添加一个子窗口时,我会收到一个错误,或者新窗口没有打开。
I have this:我有这个:
class SmallWindow: NSViewController {
@IBOutlet var window: NSWindow! //Window inside the .xib file
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
}
I already tried the above using NSWindowController
and NSWindow
.我已经使用
NSWindowController
和NSWindow
尝试了上述方法。
var smallwin = SmallWindow()
smallwin.window.makeKeyAndOrderFront(self)
//already tried with smallwin.window too
I am wondering how to programmatically start a new window.我想知道如何以编程方式启动一个新窗口。 Am I missing some steps?
我错过了一些步骤吗?
@IBOutlet var window: NSWindow!
@IBOutlet var smallwin : SmallWindow!
func applicationDidFinishLaunching(aNotification: NSNotification) {
smallwin = SmallWindow()
window.addChildWindow(smallwin.window, ordered: NSWindowOrderingMode.Above)
}
You probably don't need a child window.您可能不需要子窗口。 You just need a window.
你只需要一个窗口。
To put a new window on the screen, you need to do three things:要在屏幕上放置一个新窗口,您需要做三件事:
Create the window, either programmatically or by loading a nib.以编程方式或通过加载笔尖来创建窗口。
Send an order-in message to the window.向窗口发送订购信息。 Usually you want to send
makeKeyAndOrderFront
or orderFront
.通常你想发送
makeKeyAndOrderFront
或orderFront
。 See “Opening and Closing Windows” in the Window Programming Guide .请参阅Window Programming Guide中的“打开和关闭 Windows” 。
Keep a strong reference to the window.保持对窗口的强烈参考。 The system doesn't necessarily keep a strong reference to an on-screen window.
系统不一定保持对屏幕窗口的强引用。 If the window is deallocated, it will remove itself from the screen.
如果窗口被释放,它会从屏幕上移除自己。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.