I have a UIViewController that I load every time I click a button:
NearMe * temp = [[NearMe alloc] initWithNibName: @"NearMe" bundle:nil];
I parse some XML with locations and then assign the values to an NSMutableArray, which populates a UITableView.
I parse the XML on the viewDidLoad method, but I don’t need to parse it every time, since the value is not going to change. I only want to parse it if the array is nil, so I put the following check in:
if (allLocations == nil) ....
So that the XML is only parsed if necessary, but every time I press the back button (in the UINavigationController) it erases all the objects in the array…. I don’t have any idea why this is happening…
Since your app is creating a new
NearMeinstance each time, theallLocationsinstance variable will always benilinviewDidLoad(which, by the way, is only called if the_viewinstance variable isnil).If you don’t want to recreate the array each time, your app will need to cache it somewhere else. A couple of possibilities would be to store the array in the object that creates the
NearMeinstance, or to store it in a static variable.