0
votes

I am writing an app which will step through a bunch of data and when it hits upon a certain condition I would like to display a custom dialog allowing the user to edit some info for the data. I have tried using a modal seque.

However when I run the code it opens all the dialogs at once. It continues to step through the data even if a "modal" dialog is open.

Example:

for x in 1...10 {
    print("X is: \(x)")
    self.presentAsModalWindow(sheetViewController)
}

This will display 10 windows...it does not act truly modal.

I would like it work like an NSAlert where execution stops till the dialog is dismissed. A NSAlert will not work because I need textbooks and other controls on the modal window.

Does anybody have any ideas how to accomplish this?

Thanks in advance!

1

1 Answers

0
votes

Instead of presentAsModalWindow, Use

NSApp.runModal(for: NSPanel(contentViewController: sheetViewController))

And in your SheetViewController you have to close the modalWindow depending on logic.

@IBAction func buttonClicked(_ sender: NSButton) {

    if NSApp.modalWindow == self.view.window && NSApp.modalWindow!.isVisible {

        NSApp.stopModal() // Use .stopModal(withCode: .OK) if response has to be sent
        self.view.window?.close()
    }
}