当我保存数组时,一切都很好
NSMutableArray *savestring = news;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:@"savestring"];
[defaults synchronize];
这NSLog
是一个标题,大约 10 个标题(从输出中很简单):
2013-08-19 11:23:13.556 Dr.Saleh[4282:1303] saveString= (
"Sumou Real Estate Company Won The Award of the World Confederation of Business"
)
2013-08-19 11:23:13.558 Dr.Saleh[4282:1303] saveString= (
"Biggest indoor Mapping Projection event"
)
2013-08-19 11:23:13.559 Dr.Saleh[4282:1303] saveString= (
"Sumou Real Estate launches"
)
.......ETC
然后当我加载字符串时,它只取最后一个字符串,这是加载代码:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *loadstring = [defaults objectForKey:@"savestring"];
[defaults setValue:loadstring forKey:@"savestring"];
news = [defaults mutableArrayValueForKey:@"savestring"];
NSLog
新闻只给了我最后一个字符串保存在保存字符串中我的错误在哪里
//================================================= ============================//
我通过更改此代码解决了我的问题
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:@"savestring"];
[defaults synchronize];
让它像那样
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] setObject:[[[NSUserDefaults standardUserDefaults] objectForKey:@"savestring"] arrayByAddingObject:news] forKey:@"savestring"];