Reputation: 115
I am having problems working with an NSMutableArray in my program.
There is an array contained within my view controller that has strings added throughout the course of the program. The array is declared within the viewController.
NSMutableArray *tableData;
I am trying to run a method within the same view controller to save the array elements to a table. When the method is accessed through the view controller as shown below it works correctly
[self saveData];
When I call the same saveData method through the app delegate the array does not seem to contain any data.
listView is the object within the appDelegate to reference the view controller containing the save method.
ListAppViewController* listView = [[ListAppViewController alloc] init];
[listView saveData];
This method is being called from the applicationWillTerminate method. I'm thinking the array elements are not available to the appDelegate and that's why the count is 0?
Upvotes: 0
Views: 437
Reputation: 17612
When you do ListAppViewController* listView = [[ListAppViewController alloc] init]
, you create a new instance of the view controller. If the intention is to save any data you had in that view controller, this won't work (as you're not accessing the instance your app has been using).
Here's how you can do what you want:
applicationWillTerminate
method ListAppViewControllerList
[self saveData]
in the notification handler.Upvotes: 2
Reputation: 119021
applicationWillTerminate
is basically never called. You need to trigger the save when the app goes to the background (resigns active).
Upvotes: 2