I'm making an app that uses a UITableViewController
, and fills that table view with data from a webserver.
Inside my viewDidLoad
I have a method that loads data from said webserver, stores it in an array as custom objects, and then loads that into cells. This is working fine.
Problem:
However, every time I navigate away from that UITableViewController
, and then back, it loads everything again. This is very unnecessary, so what I did was store a boolean
in the NSUserDefaults
, which keeps track of whether or not this is the first time starting the app. If it is (you just logged in), load the data from the server. If not, don't.
However, as I noticed, the tableView
resets every time I navigate away from (or back to) the Controller
. Also, all the arrays I stored the custom objects in are now empty, so I can't load it back from the arrays either.
(Every time I navigate back to the TableViewController
, it's empty)
I tried storing the arrays in the NSUserDefaults
, and then just populate the tableView
with that data every time, but it turns out I can't store custom objects in the NSUserDefaults
.
What I want to achieve is this:
Whenever I navigate away from and back to said TableViewController
(I use the SWRevealViewController
), I don't want the tableView
to empty out. I want all the cells to stay, that way there is no wait time between when the view
is loaded and the tableview
is filled.
If this is impossible, I want the second best. To store the array somewhere in the app, and then reload that data into the tableview as soon as the user navigates back to the TableViewController
. This is slower than my preferred solution, but still quicker and less data-consuming than loading everything from my server.
Any help is appreciated!
Thanks.