在segue之间传递数据,而无需使用PrepareForSegue [英] Passing data between segues without using PrepareForSegue

查看:87
本文介绍了在segue之间传递数据,而无需使用PrepareForSegue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用情节提要创建一个5个步骤的用户设置帐户.每个步骤都有一个ViewController:1º)输入名称,联系人等,2º)导入照片,3º)输入,等等4º)更多输入5º)确认页面,如果用户单击确认"->获取所有输入并上传到解析.

当我在线搜索时,唯一的解决方案是创建一个功能准备Segue"并传递信息...但是对我而言,这没有任何意义:

如果我有1000个视图控制器,那么第一个视图控制器信息将通过所有1000个视图控制器传递?为什么nº1000视图控制器无法获取所有遗留的信息?例如:Viewcontrollernº50不需要有关viewcontrollernº1的信息...这是胡说八道.

还有其他方法可以实现吗?

也许有一种解决方案,因为我像在使用Parse一样使用Parse:

ParseClass [名称"] = textfield.text

它将信息发送到Parse,并且它们一直保存到我执行诸如SaveInBackground()之类的操作为止.

我正在尝试使用Viewcontrollers查找类似的解决方案.每个Viewcontroller都会发送信息以解析并保留该信息,直到在Viewcontrollernº5上发生"saveinbackground()"为止.

可能吗?谢谢

解决方案

是可以的.您可以使用NSUserDefaults将信息存储到内存中,一旦存储,您就可以在项目中的任何地方使用它.

就像您可以通过这种方式存储价值一样:

NSUserDefaults.standardUserDefaults().setObject(yourObject, forKey: "yourKey")

现在,您可以使用yourKey从任何地方检索此信息,如下所示:

let yourInstance = NSUserDefaults.standardUserDefaults().objectForKey("yourKey")

并且您可以根据需要强制转换它的类型.

有关更多信息,请阅读适用于NSUserDefaults的Apple文档.

另一种使用ClassStruct将值从一个视图传递到另一个视图的方法,而无需保密.

您可以从 Get all the inputs and upload to Parse.

The only solution i get when i search online for this, is to create a func "Prepare for Segue" and pass the information...But for me, this doesnt make any sense:

If i had 1000 viewcontrollers, the first viewcontroller information will be passsed through all the 1000 viewcontrollers? Why not the nº1000 view controller getting all the information that was left behind? e.g: The viewcontroller nº50 dont need the information about the viewcontroller nº1... This is a nonsense.

Is there any other way to implement this?

Maybe there is a solution since i'm using Parse like when i do:

ParseClass["Name"] = textfield.text

It sends information to Parse and they hold it until i do something like SaveInBackground().

I'm trying to find a solution like this using viewcontrollers. Each viewcontroller send information to parse and hold the information until the "saveinbackground()" happens on Viewcontroller nº5.

Possible? thank you

解决方案

Yes it is possible. You can use NSUserDefaults for that which will store your info into memory and once it is stored you can use it anywhere in your project.

Like you can store value with it this way:

NSUserDefaults.standardUserDefaults().setObject(yourObject, forKey: "yourKey")

Now you can retrive this info from any where with yourKey like this:

let yourInstance = NSUserDefaults.standardUserDefaults().objectForKey("yourKey")

And you can cast it's type as per your need.

For more Info read Apple Document for NSUserDefaults.

One more way to pass value from one view to another view without segue by using Class or Struct.

You can read more about Classes and Structures from Apple Documentation.

这篇关于在segue之间传递数据,而无需使用PrepareForSegue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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