1
votes

I have a NSWindowController (with a relationship to NSViewController) in a storyboard and I need a sheet to load over the NSWindowController's window (well, the whole app actually). I am using the beginSheet method but that only loads the sheet to the side and it does not disable the window behind it. If I add a toolbar to the NSWindowController with a button to load the sheet, it works perfectly. Unfortunately, I need this sheet to load at app launch.

In a previous app where I used no storyboard, just xibs, I loaded sheet window with the beginSheet method in the app delegate's applicationDidFinishLaunching method but again if I try same setup in this app, sheet only loads to the side of this app with no disabling of main window.

Visible at launched is unchecked. (I've searched enough to see this is usually the issue for people.)

var sheetWindow = NSWindow(contentRect: NSMakeRect(0, 0, 600, 150), styleMask: NSTitledWindowMask, backing: NSBackingStoreType.Buffered, defer: true)

self.window!.beginSheet(sheetWindow, completionHandler: nil)

In my connections inspector in IB, for the Window Controller's window, I have it set as the Window Controller's window and I have the Window Controller as its delegate.

Even trying to call the same method called with the toolbar button in my windowDidLoad method of the NSWindowController, still loads disconnected from its window.

Any direction would be greatly appreciated, I have come up with nothing all day. I am using Yosemite.

1
Can you add screenshots of your problem?Cristik

1 Answers

1
votes

I was able to solve it by placing the code in viewDidAppear() on the ViewController class but attach the sheet to the WindowController's window.

var sheetWindow = NSWindow(contentRect: NSMakeRect(0, 0, 600, 150), styleMask: NSTitledWindowMask, backing: NSBackingStoreType.Buffered, defer: true)

let windowController = self.view.window?.windowController() as! windowController
windowController.window!.beginSheet(sheetWindow, completionHandler: nil)