M
M
Max Vecheslavov2016-11-08 08:53:54
Swift
Max Vecheslavov, 2016-11-08 08:53:54

How to pass data back after seque?

Hello!
[here is a standard introduction about a beginner learning swift 3...]
There are two ViewControllers: the main window, and the Popover window. How to transfer data to the Popover window is clear, through Seque. But how then to transfer the data back, when the window is closed?
For example, the main program window has an NSTextField and a button. When the button is pressed, a popover is shown, where we enter some value into another NSTextField. So how do you pass this value to the first NSTextField when the window closes?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Donkovtsev, 2016-11-08
@veche

Search Google for "delegate", in short, you create a protocol in which you write methods that save data in the parent class, then add a variable to the child class (popover) and when it is closed through this variable, you access the parent class.
Pseudocode:
protocol DataSaver {
func savePopoverData(myData);
}
class Parent : DataSaver {
myData: [Int];
func savePopoverData(myData) {
self.myData = myData;
}
}
class Popover {
delegate: DataSaver;
func onClose() {
self.delegate.savePopoverData(myData);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question