Cyph3r Cyph3r - 4 months ago 16
iOS Question

NSUserDefaults data not Working

I have implemented a

UITableView
in VC1 to display firstName and LastName of the user,and a edit Button at the top of the
UITableView
. When the user presses the button it navigates through navigation controller to VC2.

In VC2 the user can update the
firstName
and
LastName
Fields. I am saving the details Using
NSUserDefaults
as

NSUserDefaults*first=[NSUserDefaults standardUserDefaults];
[first setValue:textField1.text forKey:@"firstname"];


While I go back to VC1 and try to display the updated data its not working why is it so...?

NSUserDefaults*first=[NSUserDefaults standardUserDefaults];
cell.detailTextLabel.text=[first valueForKey:@"firstname"];


How can I do it using
NSUserDefaults
.?

Answer

NSUserDefault is working fine, you just need to reload your table on viewWillApear event.

//In VC1

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [_yourTableView reloadData];
}
Comments