When I replace the @"hello" with titlestring the table, the cell shows up blank, If i leave the hello, everything works, including the “detailsstring”. I don’t know why it’s doing that since detailsstring is set up exactly the same as titlestring.
here is the code:
in the .m file I have
@synthesize detailsstring;
@synthesize titlestring;
and it’s all defined the same in the .h in the .m I have this as well:
- (void)viewDidLoad{
titlestring =[[NSUserDefaults standardUserDefaults] objectForKey:@"titletext"];
detailsstring = [[NSUserDefaults standardUserDefaults] objectForKey:@"details"];
tabledata = [[NSArray alloc] initWithObjects:@"hello", nil];
tablesubtitles = [[NSArray alloc] initWithObjects:detailsstring, nil];
[super viewDidLoad];
}
Now, I’m saving those Userdefaults in another controller. Here is the save button action in a different view controller:
- (IBAction)saveButton:(id)sender {
NSUserDefaults *titletext = [NSUserDefaults standardUserDefaults];
[titletext setObject:titleTextfield.text forKey:@"titletext"];
NSUserDefaults *details = [NSUserDefaults standardUserDefaults];
[details setObject:detailstextfield.text forKey:@"details"];
NSUserDefaults *categoryUser = [NSUserDefaults standardUserDefaults];
[categoryUser setInteger:selectedCategory forKey:@"category"];
}
What am I doing wrong?
First of all, one instance of
NSUserDefaultsis sufficient for all three modifications. To ‘push’ the changes to the file system immediately, you can call[userDefaults synchronize];. Otherwise there is no guarantee that your changes are saved instantly. Apple suggests only to call this method if you cannot wait for the changes to be saved.In your
viewDidLoad:method, try to output the saved values to test your application’s integrity: