NSUserDefaults overwriting new values with old
I have a bunch of userdefaults value that I use to load my UITableView in
-(void) prepareDisplay
{
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
table.dataSourceArray = [standardUserDefaults objectForKey:@"dataSource"];
}
-(void) viewDidLoad method {
开发者_如何学JAVA [self prepareDisplay];
}
and it works fine up to this point.
Then at a later point I change the userdefaults value and synchronize. Then I have to reload my table again. But before that I need to set the datasource array using the same
- prepareDisplay () method.
Here I think that the instance of userdefaults that I created in my viewDidLoad earlier is overwriting or messing up with my userdefaults value and it calls up the old values again and not the newly set value.My newly set userdefaults value get overwritten with the old values. I have checked the plist file in the application sandbox after I do the userdefaults resetting and the values are reflected properly. But later, I don't how and when, they get overwritten with the old values. I am sure there is nothing I am doing explicitly to mess them up after resetting.
Can anybody help. Thanks
Actually you don't need an instance variable for NSUserDefaults
because it is a singletone object. Avoid it. Additionally you may check the method - (BOOL)synchronize
of the same object which Writes any modifications to the persistent domains to disk and updates all unmodified persistent domains to what is on disk.
精彩评论