I'm trying to set the position of a modal sheet in a ViewController. What I´ve got so far is this:
import Cocoa
class ViewController: NSViewController, NSWindowDelegate {
func window(_ window: NSWindow, willPositionSheet sheet: NSWindow, using rect: NSRect) -> NSRect {
print("function entered")
}
var sheetWindowController: SheetWindowController!
@IBAction func showSheet(_ sender:AnyObject){
let windowController = SheetWindowController(windowNibName: "SheetWindowController")
self.sheetWindowController = windowController
self.sheetWindowController.delegate = self
self.view.window?.beginSheet(self.sheetWindowController.window!, completionHandler: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.window?.delegate = self
}
}
It is working as far as the sheet shows up on the top of the window. But the willPositionSheet
method doesn't get called. Any idea what is missing?