开发者

iPhone: How do I retain the values after switching to another view and returning back to the same view?

How do I retain the values after switching to another view and returning back to the same view?

Is there a way to retain the array even after the view disappears?

My Array shows the values in console first time, but second time when it returns from other view the array shows (null)

EDIT:

I a开发者_运维问答m using this array to use it into my core-plot.

This array contains the plot points for the core-plot


Generally speaking you have a few options to maintain data persistence between views. In no particular order:

  1. Pass the array back and forth between the views. This involves creating a property on each view and setting it. You can use properties directly but you might have an easier time using NSNotifications to pass the data around.

  2. Store the data in Core Data, loading lazily as needed. This is the most powerful option and may be a bit much. Core Data is not the correct way to "pass data between views", but often may be what you need. As an added bonus, your data stays saved across app launches.

  3. Store the data in your delegate. This is similar to using NSNotofications. All of your objects can access the delegate more easily than passing references to each other all over the place.

  4. Store the array in NSUserDefaults, assuming your data is compatible. This is similar to Core Data in that it offers persistence, but is much more "lightweight" and less powerful. Note that some objects are incompatible with NSUserDefaults.

Edit:

For storing an array of points, I would serialize it into either Core Data or NSUserDefaults, depending on how the user interacts with the data and how much data there actually is. If the points change often and there are many of them, look into Core Data. Although, you can do just fine with an array in NSUserDefaults. You just end up doing more array manipulation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜