Passing data from the FirstViewController to the LastViewController

后端 未结 3 917
再見小時候
再見小時候 2020-12-22 01:13

I have four viewControllers in my current design and I am designing an app to sell a product.

FirstViewController gets the product image and when user

3条回答
  •  爱一瞬间的悲伤
    2020-12-22 01:38

    One way of doing this would be that you create a mutable dictionary (or a custom object with variables) in the first view controller. Then you would pass a weak reference to second/third/fourth view controllers of the mutable dictionary/object from first view controller. Each view controller would be able to set data to the dictionary/object and the last one would be able to process the information.

    Another way would be to create a simple singleton class with variables that you want to store. The first view controller would reset the singleton variables. Then let each view controller access the singleton and store their values there, last view controller would process values from singleton.

    It depends how many data you are collecting and what you personally prefer.

提交回复
热议问题