macOS,Swift 3:segue之后如何取回数据? [英] macOS, Swift 3: How to get data back after segue?

查看:130
本文介绍了macOS,Swift 3:segue之后如何取回数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:我有两个UIViewController.第一个具有按钮和NSTextField,第二个仅具有NSTextField.

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.

将一些数据从第一个控制器传输到第二个控制器并不重要-我使用segue.但是,我应该怎么做才能将数据从弹出窗口转移回主窗口? 例如::我们打开弹出窗口,在NSTextField中键入一些文本,我想在第一个ViewControllerNSTextField中获得此文本.

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.

我找不到答案:-(

推荐答案

在macOS中,如果使用情节提要和segues,则非常简单.

In macOS it's pretty easy if you are using storyboard and segues.

NSViewController具有属性presenting,其中包含对父视图控制器的引用.

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)

这篇关于macOS,Swift 3:segue之后如何取回数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆