How to pass data between different UIViewControlle

2019-05-30 05:06发布

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.

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-05-30 05:28

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.

查看更多
家丑人穷心不美
3楼-- · 2019-05-30 05:46

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!

查看更多
登录 后发表回答