我試圖在設備上保存NSMutableArray,但每次我重新加載應用程序時,數據都將被刪除。無法在NSUserDefaults中保存NSMutableArray
我試圖用NSUserDefaults的,但問題仍然存在
這裏是代碼我使用
-(void) addingData{
[data addObject:theBarcodeString]; //data is the NSMutableArray
[mainTableView reloadData]; //this is a UITableView where the data from the NSMutableArray is populated
[self endText];
history=[NSUserDefaults standardUserDefaults];
[history setObject:data forKey:@"history" ];
}
這裏是我加載數據
- (void)viewDidLoad
{
...
if (data == nil) {
data = [[NSMutableArray alloc] init]; //onload it always goes to his line
else {
data=[[NSUserDefaults standardUserDefaults] objectForKey:@"history" ];
}
...
}
我在做什麼錯了?
你爲什麼要測試'data == nil'? – kennytm 2011-12-20 14:29:17
查看數據是否已經保存在NSMutableArray中 – user1051935 2011-12-20 14:30:02