Best way to load an application like it was in its previous state when it was terminated

主宰稳场 提交于 2019-12-06 04:51:04

Building on what Marc said, assuming you've got a base view controller, and then one or more levels of 'drill-down', load all your view controllers up to the 'current' one using [navigationController pushViewController: viewController animated: NO]. Then, when the user hits the Back button, they'll be presented with the pre-loaded previous view controller. A good example of this is the "Contacts" app, which preloads the Groups view controller, then pushes a view controller for the current group (usually "All Contacts") on top of that.

Check Apple's DrillDownSave sample app:

"Demonstrates how to restore the user's current location in a drill-down list style user interface and restore that location when the app is relaunched."

http://developer.apple.com/iphone/library/samplecode/DrillDownSave

You'll need to associate an identifier with each view controller, and save that value to the user defaults when the current view changes. The next time you launch, read that value and you'll know which view controller you need to load initially.

I've published a little library to help doing these kinds of things. I'm already using it in an app I've published on the App Store and it's a lot smoother than implementing NSCoder for every view manually :P

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!