I have a tableview which shows a webview on clicking some row in the table, which in turn picks up the data from an sqlite. if a user closes the app by pressing home key while viewing a description in webview and reopens it after sometimes, I should be making the user to see the same screen. how to show the same view again ? What is the efficient way ?
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.
Related
Suppose user is at any viewcontroller in app and filling the form the (view controller can be any viewcontroller).
Now he quits the app also from background.
So when user again starts the app i need to show the viewcontroller with same status he had quit it.
You'll have to save those field values - and what view is being shown - to some persistent storage (write to a plist for example)...depending on the layout of your app, you could do that each time the applicationWillEnterBackground, or applicationWillTerminate, or maybe every time textFieldDidEndEditing...then you'll need to recall that data on re-launch
http://www.edumobile.org/iphone/iphone-programming-tutorials/data-persistence-in-iphone/
What is the first method that gets called in the UIApplication Delegate? I have included a launch image in my application, and I would like to get a head start on downloading some data while that screen is still up, before my actual views appear. Should I be looking to place these calls in the delegate, or where is the first place I should think about making these calls?
- (void)applicationDidFinishLaunching:(UIApplication *)application
gets called first.
EDIT:
Your Default.png appears for short time when the app is launched. You cannot rely on this short time to do some processing.
You can show your first view with a message that download is in process (with the help of activity indicator view)
Consider the First answer(as - (void)applicationDidFinishLaunching:(UIApplication *)application called at all first), BUT if you want to display your downloaded image on your first view, then implement some delay (BY Timer or something till your image download), and yeah don't forgot to implement an in between screen with activity initializar(otherwise your application will seem like hanged).
I need to get the name of the view the user is currently viewing as an NSString, in order to save it so that I can return the user to this view if they exit my app. As of now, if a user exits my app on "View4" for instance my app will return them to "View1" if they launch it even immediately afterwards.
P.S. I know this is possible because many apps, such as tap tap revenge and angry birds do this. You can quit at any time and return, and the view and everything you were at will be saved.
Save the view name using NSUserDefaults. Then, when you app launches, try to retrieve the name from user defaults.
I have 2 views. When I'm on the 1st view, I have a textfield. I enter some text in the textfield. I exit the app, launch some another application and then return to my application. I want to maintain state of the textfield and that view. Likewise, if I quit with the 2nd view active, when I return to the app I need to return the view to the state it was in when the app quit.
How do I save the information about the state of my app when it last quit so I can recreate it upon the next launch?
Use the NSUserDefaults to write the value and selected view index to the user's preferences.
Apple's DrillDownSave sample may be helpful
I am having trouble finding some information on persistence in iPhone apps. I am creating a tab based - navigation based app and want the application to save the current location when the app quits. For example if the user is in tab 1, several tiers into the navigation controller and the app quits, I would like the app to load up in the same place the next time it loads.
If anyone can point me in the direction of a good book/tutorial that would be great.
Cheers
Just to make it clear, I know that I would need to save the data somewhere and that NSUserDefaults seems to be the best way to do this. What is confusing me is what to actually save when the app is closed and then how to load it so that the correct view is loaded.
NSUserDefaults
http://icodeblog.com/2008/10/03/iphone-programming-tutorial-savingretrieving-data-using-nsuserdefaults/
Obviously, you'll need to save the tab you're displaying, and whatever sort of data storage you want to use to manually determine where the user is. If you're using a drill-down sort of system where your data is in arrays that the user opens, then I would suggest saving an NSIndexPath of the items the user clicked on to get to his current position.
Then, on app startup, first switch to the correct tab, then load the index path and create the necessary views and set the navigation controller's stack using [navigationController setViewControllers:animated:]