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

查看:111
本文介绍了在没有Segues的故事板之间传递变量 - 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变量(String)喜欢将我的数据传递给我,我已经知道如何在不同故事板中的两个视图之间移动。像这样。

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的故事板之间传递变量 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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