Sunday, 8 September 2013

NSUserDefaults doesn't work

NSUserDefaults doesn't work

I am new in programming and i have one problem. I create app, with two
views. First is tableviewcontroller and second is view controller. from
second view i sending data into my tableview trough perepareForSegue
method. My data (Strings) are NSMutableArray and this MutableArray i want
to save into UsedDefault after my app didEnterBackgoung in appDelegate.m
Then i want to load it back, but nothing happened. I put my code in
appDidBecomeActive in appDelegate.m and i already try write it in my first
view viewDidLoad, but no action. My MuttableArray is still empty, after
new app start.
here is my code:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
self.flipsideView.zoznamFunkcii = [[NSMutableArray alloc]init];
NSUserDefaults*defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:self.flipsideView.zoznamFunkcii
forKey:@"NSMutableArray"];
[defaults synchronize];
}
flipsideView is my first View and zoznamFunkcii is my NSMuttable array
and this is my load method:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
self.flipsideView.zoznamFunkcii = [[NSMutableArray alloc] init];
NSUserDefaults*defaults = [NSUserDefaults standardUserDefaults];
self.flipsideView.zoznamFunkcii = [defaults objectForKey:@"NSMutableArray"];
}
Can anyone help me with that? I don't know why it not work.

No comments:

Post a Comment