IBOutlet nil after closing NSWindow sheet - swift

182 views Asked by At

I have an NSWindowController class connected to an .xib that I present as a sheet with the following method in my main ViewController:

func openSheet() {
    var modalSheet = NSWindowController()
    modalSheet = modalWindow(windowNibName: "modalWindow") as modalWindow
    self.view.window!.beginSheet(modalSheet.window!, completionHandler: nil)
    modalSheet.window!.delegate = self
}

modalWindow being the name of the NSWindowController sheet class.

In my modalWindow class I have the following method:

@IBAction func cancel(sender: AnyObject) {
    var delegate: NSWindowDelegate? = ViewController() as NSWindowDelegate
    var nsn = NSNotification(name: "", object: nil)
    println("Closing Modal Window. Saved data: \(data)")
    self.window!.close()
    delegate!.windowWillClose!(nsn!)
}

Now when I call the protocol method in my main ViewController:

@IBOutlet var path1: NSTextField!

func windowWillBeginSheet(notification: NSNotification) {
    path1.stringValue = "abc"
}

path1 shows up as nil. Any help or guidance on fixing the issue of path1 showing up as nil would be greatly appreciated.

0

There are 0 answers