在View Controller之间传递数据而不会造成干扰 [英] Passing Data between View Controllers without segue

查看:44
本文介绍了在View Controller之间传递数据而不会造成干扰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设计碰壁了.我正在尝试将字符串从一个View Controller传递到另一个.这两个控制器未与segue连接.我已附上我的情节提要的屏幕快照.我觉得我唯一的选择是使用Singleton,还是可以使用委托人呢?不使用方法:

I have hit a wall with my design. I am trying to pass the strings from one View Controller to another. Those 2 controllers are not connected with segue. I have attached the screenshoot of my Storyboard. I have a feeling that my only option is to use a Singleton, or would that be possible with delegates? without using the method:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) 

我无法通过segue标识符访问VC1.不访问标识符怎么办?

I can not acces the VC1 by the segue identifier. How would that be possible without accessing the identifier?

请查看图片,并让我知道我有哪些选项以及在此处最好使用的选项.

Please have a look at the image and let me know what options do I have and what would be the best to use here.

推荐答案

如果它是一些字符串或变量之类的小数据,则可以使用 UserDefault 或使用该类变量(例如vc2.data =)传递数据数据如何使用UserDefaults 如何快速使用UserDefaults?

If its a small data like some string or variable you can use UserDefault or pass data using that class variable like vc2.data = data How to use UserDefaults How to use UserDefaults in swift?

如果它更像表格或用户列表数,则可以使用捆绑包中的 plist 存储,可以从任何视图控制器检索使用Plist 如何将plist作为Swift中的字典?

If its more like table or number of user list you can use plist store in your bundle at can retrieve from any view controller using Plist How do I get a plist as a Dictionary in Swift?

如果两个控制器之间有某种连接方式,则可以使用代表.delegats:-迅速派代表参加会议吗?

if two controller are some how connected you can use delegates. delegats:- Delegates in swift?

如果不确定数据何时可用/不确定,也可以使用通知.或者如果触发某些操作则发送

.

You can also use notifications if you are not sure when data will be available/ or send base on some action, or send if something is trigged.

使用通知传递数据如何在swift 3.0中使用NotificationCentre和在swift 2.0中使用NSNotificationCenter传递数据?

这篇关于在View Controller之间传递数据而不会造成干扰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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