我正在从另一个ViewController展示NSViewController
。
[self presentViewControllerAsSheet:secondViewController];
这是NSWindow
的方法
- (void)beginSheet:(NSWindow *)sheetWindow
completionHandler:(void (^)(NSModalResponse returnCode))handler;
对于带有完成处理程序的NSViewController
,是否有上述等效方法。
答案 0 :(得分:0)
够了吗?
class SOMEViewController: NSViewController {
private var parentWindow : NSWindow? = nil
public func beginSheetModal(for parentWindow: NSWindow,
handler : @escaping (NSApplication.ModalResponse) -> Void) {
self.parentWindow = parentWindow
guard let sheet = self.view.window else { return }
parentWindow.beginSheet(sheet, completionHandler: handler)
}
public func endSheet(_ response : NSApplication.ModalResponse) {
guard let parent = self.parentWindow else { return }
guard let sheet = self.view.window else { return }
parent.endSheet(sheet, returnCode: response)
}