简体   繁体   English

如何在不同的UIViewControllers之间传递数据?

[英]How to pass data between different UIViewControllers?

What is the best way to pass data from one view controller to another? 将数据从一个视图控制器传递到另一个视图控制器的最佳方法是什么?

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? 另外,如何将数据从推送视图传递到早期视图?

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. 我不想使用plists或sqlite,因为数据不是那么重要。

Keeping the data in AppDelegate is not a good idea if the amount of data is quite large since the data will live throughout the application lifecycle. 如果数据量很大,则将数据保留在AppDelegate中不是一个好主意,因为数据将在整个应用程序生命周期中均有效。

Why not call the setter(s) of the newly created UIViewController object to pass the data so that you can release it if the view goes offscreen or gets deallocated. 为什么不调用新创建的UIViewController对象的setter传递数据,以便在视图离开屏幕或释放时可以释放数据。

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 . 为什么不尝试在AppDelegate创建变量,将该数据提供给AppDelegate变量,然后在应用程序或UIViewControllers任何位置获取该数据,则该值将分配给该应用程序的变量委托termination application

Try taking help from already asked several times Pass Data Between Several Viewcontrollers in a App. 尝试从已经问过几次的问题中寻求帮助, 在应用程序的多个Viewcontroller之间传递数据。

Hope you get my point .....Good luck! 希望你明白我的意思...祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在UIViewControllers之间传递数据 - pass data between UIViewControllers 如何在UIViewControllers与协议/委托之间传递数据 - How to pass data between UIViewControllers with protocols/delegates 如何在UIViewControllers之间传递数据而不显示它 - How to pass data between UIViewControllers without presenting it 如何在UIPageViewController中的UIViewControllers之间传递数据并保存变量 - How should I pass data between UIViewControllers in UIPageViewController and save variables 如何通过@objc函数在UIViewControllers之间传递数据数组 - How to pass array of data between UIViewControllers from @objc function 如何在布局类似于叉子的UIViewControllers之间导航和传递数据? - How to navigate and pass data between UIViewControllers whose layout resembles a fork? 如何在UITabBarController中的两个UIViewControllers之间传递信息 - How to pass information between two UIViewControllers in a in a UITabBarController 在UIViewControllers之间传递UILongPressGestureRecognizer - Pass UILongPressGestureRecognizer between UIViewControllers 如何在两个UIViewcontrollers之间跳转 - How to jump between two UIViewcontrollers 从UIDatePicker在UIViewControllers之间传递数据 - passing data between UIViewControllers from UIDatePicker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM