Jesse Durham
Jesse Durham

Reputation: 285

Possible to go back to previous view using Nav Bar and not lose View's data?

I have an app that populates list views when a view is created. I would like to be able to navigate with a back button and go back to a previous screen and have the data that was listed still be there. Is this possible?

What seems to be happening with basic creation of a back button, is when I press it, the view starts up like it was brand new, expecting data input to populate the list. Is it possible to have the state of the previous screen saved? rather than it be wiped out and have to be re-populated when using a back button? I would rather not have to ping the server I get the data from every time a user presses the back button. Especially if the data has already been grabbed once already.

In other words, I'd like it to work like a web browser, where the state of the screen is saved and pressing back just loads what was there, rather than pinging the website again for all of its data.

Thanks.

Upvotes: 1

Views: 210

Answers (2)

The dude
The dude

Reputation: 7924

You could also use NSUserDefaults to store the data, instead of Core Data. It depends on the data you plan to store.

Update 1 Here is an example to use NSUserDefaults

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray* recentlyViewedPhotos = [[defaults objectForKey:@"recentlyViewedPhotos"] mutableCopy];
//Edit your object here
[defaults setObject:recentlyViewedPhotos forKey:@"recentlyViewedPhotos"];
[defaults synchronize];

Upvotes: 0

wattson12
wattson12

Reputation: 11174

Definitely possible. The best approach would be to store the data for the list in core data, then whenever your view appears you can check to see if you have data saved, and if not, go to the network and populate the data

Upvotes: 2

Related Questions