如何在不同的UIViewControllers之间传递数据? [英] How to pass data between different UIViewControllers?

查看:50
本文介绍了如何在不同的UIViewControllers之间传递数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个视图控制器向另一个视图控制器传递数据的最佳方法是什么?

假设我将另一个视图控制器推到当前的视图控制器上.如果必须向从当前视图控制器推送的视图提供一些数据,该怎么办?

Suppose I push another view controller onto the present view controller. If I have to give some data to the view being pushed from the present view controller how do I do it?

我又如何将数据从推送视图传递到先前的视图?

Also how do I pass data from the pushed view to the earlier view?

到目前为止,我已经通过在每个控制器中声明函数并调用它们来完成此操作.我发现它很脏,想要一种更清洁的方法来执行此操作.我不想使用plists或sqlite,因为数据不是那么重要.

So far I have done this by declaring functions in each controller and calling them. I find it dirty and want a cleaner way to do this. I don't want to use plists or sqlite as the data isn't that significant.

推荐答案

为什么不能尝试在 AppDelegate 中创建变量.将该数据提供给AppDelegate的变量,然后在任何地方获取想要在您的应用程序或 UIViewControllers 中获得该数据.该值将分配给应用程序委托的变量,直到应用程序的终止 .

Why can,t you try making the variable in AppDelegate.Give that data to the variable of the AppDelegate and fetch it wherever you want in your application or UIViewControllers you will get that data.That value will be assigned to the the variable of the app delegate upto the termination of the application.

尝试从已经问过几次的问题中寻求帮助

Try taking help from already asked several times Pass Data Between Several Viewcontrollers in a App.

希望你明白我的意思.....祝你好运!

Hope you get my point .....Good luck!

这篇关于如何在不同的UIViewControllers之间传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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