Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question