简体   繁体   中英

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.

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.

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM