NSMutableArrayをデバイスに保存しようとしていますが、アプリケーションをリロードするたびにデータが消去されます。NSMutableArrayをNSUserDefaultsに保存できません
私は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
がNSMutableArrayに既に保存されているかどうか確認してください。 – user1051935