问题
For example: I have two UIViewController
s. The first has a button and a NSTextField
, and the second has a NSTextField
only.
When I click the button on the first controller — the second controller shows as popover window.
Making a transfer of some data from first controller to second is not big deal — I use a segue. But what I should to do to transfer data back — from the popover window to main window?
For example: we open the popover window, type some text in NSTextField
, and I want to get this text in the NSTextField
of the first ViewController
.
I can't find the answer :-(
回答1:
In macOS it's pretty easy if you are using storyboard and segues.
NSViewController
has a property presenting
which contains a reference to the parent view controller.
Obtain the reference, call a method in the parent view controller to pass the data and dismiss the child view controller.
let firstViewController = presenting as! FirstViewController
firstViewController.passDataBack(data)
self.dismiss(self)
来源:https://stackoverflow.com/questions/40481432/macos-swift-3-how-to-get-data-back-after-segue