我試圖在ViewController中設置模態表的位置。 什麼從來就走到這一步,是這樣的:Swift模態表:willPositionSheet does not get called
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
}
}
它正在儘可能的表顯示了在窗口的頂部。但willPositionSheet
方法不會被調用。任何想法缺少什麼?
請參閱[試圖知道當一個窗口關閉在macOS基於文檔的應用程序](https://stackoverflow.com/questions/44685445/trying-to-know-when-a-window-closes-in-a- MacOS的文檔爲基礎的應用程序)。 – Willeke