I have a method that is working but its not saving the data that I enter.
This is the code I use to enter data on a
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
NSString *tempTextField = [alertView textFieldAtIndex:0].text;
if (!numbers) {
numbers = [[NSMutableArray alloc] init];
}
[[NSUserDefaults standardUserDefaults] setObject:tempTextField forKey:@"Save"];
[numbers insertObject:tempTextField atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.myTableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
} }
It is using a UIAlertView with a plain text input. I try to use an NSUSerDefaults to save the data with the method above and I'm able to retrieve the data on the viewDidLoad with this code
-(void)viewDidLoad {
[super viewDidLoad];
NSArray *siteNameValue = [[NSUserDefaults standardUserDefaults] valueForKey:@"Save"];
numbers = [[NSMutableArray alloc] initWithObjects:siteNameValue, nil];
}
But it would only save one of the data that is entered, it doesnt save multiple data. Any leads?
the variable numbers is an NSMutableArray.
NSUserDefaultsto save your app data.