简体   繁体   中英

Store data from TableView in the NSUserDefaults

if got a tableview and the user can add strings into it:

-(IBAction)textFieldDidEndEditing {

NSString *string = textField.text;
[tableArray addObject:string];
[mainTableView reloadData];
textField.text = @"";

}

how can I store the content of the tableView into the NSUserdefaults? can anybody give me a short example please?

thanks :)

try storing whole Array as an Object into NSUserDefaults

NSUserDefaults *default = [NSUserDefaults standardUserDefaults];

[default setObject:tableArray forKey:@"key"];

& now to fetch it from NSUserDefautls:

NSArray *array = [standardUserDefaults objectForKey:@"key"];

Hope this solve some sort of problem of urs. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM