在没有 Segues 的 Storyboard 之间传递变量 - Swift [英] Passing variables between Storyboards without Segues - Swift

查看:12
本文介绍了在没有 Segues 的 Storyboard 之间传递变量 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 中位于两个不同 .storyboard 文件中的两个不同 UIViewController 之间传递数据.(这是一个相当大的项目,所以我不得不把它分解成不同的故事板.)

I'm passing data between two different UIViewControllers located within two different .storyboard files within Xcode. (It's quite a large project so I had to break it up into different storyboards.)

我已经在要将数据传递到的视图中建立了一个exercisePassed"变量(字符串),并且我已经知道如何在位于不同故事板内的两个视图之间移动.像这样.

I have already established an "exercisePassed" variable (String) within the view I would like to Pass my data to, and I already know how to move between two views located within different storyboards. Like so.

var storyboard = UIStoryboard(name: "IDEInterface", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! UIViewController

//**************************************
var ex = //Stuck Here
ex.exercisedPassed = "Ex1"
//**************************************

self.presentViewController(controller, animated: true, completion: nil)

如何在不使用 Segue/PrepareForSegue 的情况下传递数据?

How can I pass the data without using a Segue/PrepareForSegue?

推荐答案

我假设您要将数据传递到的 viewController 是自定义的 viewController.在这种情况下,请在此处使用此修改后的代码:

I'm assuming that the viewController that you want to pass the data to is a custom viewController. In that case, use this amended code here:

var storyboard = UIStoryboard(name: "IDEInterface", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! MyCustomViewController

controller.exercisedPassed = "Ex1"

self.presentViewController(controller, animated: true, completion: nil)

这篇关于在没有 Segues 的 Storyboard 之间传递变量 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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