开发者

iPhone- How to save the view controller object itself?

I want to save the state of my view controller. I searched and found that I should save the state by saving state variables.

But I am interested in saving the view controller object itself. Is there any way to save the view controller obje开发者_JAVA百科ct itself so that when I restart the application I see the same view state too on which I was before closing the app. Otherwise I have to reach that state myself and that will not solve the purpose fully as somethings like (the admob ad which was displayed) could not be restored.

If I am wrong at some place or miss something please guide me.


Look into implementing NSCoding in all the classes you want to persist. If you properly implement that and then encode your object graph at a root node (like a tab bar controller or a nav bar controller) with something like NSKeyedArchiver/NSKeyedUnarchiver when your app terminates and starts up, you can save and restore the state of a view controller easily. UIViewController and UIView implement it by default, so all you need to do is override the encodeWithCoder: and decodeWithCoder: methods, call super, and save the state variables you need.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜