1

I would like to ask some suggestion about how to restore a viewControllers state. Like in the app called "Pic Collage" when you create a card and save it and later restore it.

Anand
  • 864
  • 10
  • 31
  • You mean serialization? You'll probably get a more detailed answer, but here, a few links: [Correct way to save/serialize custom objects in iOS](http://stackoverflow.com/questions/5413851/correct-way-to-save-serialize-custom-objects-in-ios), [How to serialize a class in IOS sdk (Objective-c)?](http://stackoverflow.com/questions/8921698/how-to-serialize-a-class-in-ios-sdk-objective-c)... – UIlrvnd Aug 10 '13 at 21:20
  • ok. What I am trying is to create a Card in which the user can insert images into the viewController, rotate them, resize them etc and user can insert as many as images he wants. Each image is like a layer. And later user should be able to restore (including correct rotation, resizing) – Anand Aug 10 '13 at 21:31

2 Answers2

4

If you really want to learn about state preservation, see WWDC 2012 video, Saving and Restoring Application State on iOS.

But, it's also just as likely that the app in question is simply saving the model data (the object model that represents this card) in persistent storage, and when the app re-starts, it simply loads that model data again. There are a whole bunch of possible technologies for persistent storage ranging from Core Data (robust, but a little complicated) to plists (simple, but less sophisticated). There are tons other options (archives and serialization, SQLite, JSON, etc.), but I'd rather not cloud the issue further.

I'd suggest you familiarize yourself with some of these technologies, work through a few demonstrations, and come back if you have additional questions. But this question is too broad to get into specific answers at this point.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • I had 2 things in my mind, either Core Data or may be some easy way to store whole ViewController and restore it later. I even tried to archive view from ViewController but restore does not seem to restore things. SO Core Data seemed to be the right choice. – Anand Aug 10 '13 at 21:25
  • @Joy Personally, I'd suggest you worry less on saving the view controller's state (which is designed to address a slightly different issue), and instead focus on saving model data in persistent storage. I'd suggest you dismiss the "saving the view controller" notion for now. Focus on MVC basics, saving model data in persistent storage, etc. If you mastered Core Data, first, you'd be in great shape. – Rob Aug 10 '13 at 21:30
  • 1
    Thanks for the suggestions. @Rob I have worked with Core Data in some projects (though cannot say I am expert but not newbie either). And I think in last, I'll go with Core Data choice. – Anand Aug 10 '13 at 21:35
  • 1
    @Joy Great. Core Data is more than enough to achieve what you're trying to do here. – Rob Aug 10 '13 at 21:36
0

If you are supporting iOS 6 and above, take a look at State Preservation and Restoration. Even if you have to support older versions of iOS the documentation will guide you on when and how restoration can be achieved and the things you need to consider.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • I was seeing this doc and also video from WWDC but I wasn't sure if this was the right way to go. Because State Preservation and Restoration document seems to be for when you close the app from background. – Anand Aug 10 '13 at 21:22