macOS, Swift 3: How to get data back after segue?

南笙酒味 提交于 2019-12-22 10:24:37

问题


For example: I have two UIViewControllers. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!