In didSelectRowAtIndexPath
Method of tableView , I am saving some data in NSUserDefault
like this
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
[storeData setObject:selectedCell.textLabel.text forKey:@"tpName"];
and at another place I am fetching this data with this code ,
NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
NSLog(@"tpName is %@",[storeData valueForKey:@"tpName"]);
But In this NSLog
I am getting null
value . Can Anyone suggest me where am I doing wrong ?
The
NSUserDefaults
doesn't get written out to disk until it gets synchronized. The user defaults get synchronized automatically at periodic intervals, or you can call it manually like so:If you are quitting your application shortly after the user defaults get set (without synchronizing manually), your
standardDefaults
will not be updated on disk.