how to show the same view when the app is reopened

戏子无情 提交于 2019-12-05 19:26:42

Well I think the easiest way is to store the state of the application in NSUserDefaults. There is a delegate method on UIApplication called:

- (void)applicationWillTerminate:(UIApplication *)application

This delegate method gets called when the user quits the app. This is the time where you can save the state of your application off to the NSUserDefaults. But be aware that you cannot do time intensive stuff there. If you do, you get killed by the OS.

In your case why not simply store the row the user picked in NSUserDefaults and then check in -(void)applicationDidFinishLaunching:(UIApplication *)application if there is a saved row and restore the screen approbiately.

The easiest way is to write a string to a file in your documents directory that holds your state information in some easily parsed format. For example "screen_name:database_id". Or build a JSON string and parse it with JSON.

Everytime you switch screens, rewrite the file. When you open next time, read the file, parse it, and show the appropriate screen in your app.

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