保存方法:
- (void)saveFile {
// saves data to file
NSLog(@"save file reached");
#ifdef LITE_VERSION
[self.aquariums writeToFile:[self dataFilePathLite] atomically:YES];
#else
[self.aquariums writeToFile:[self dataFilePath] atomically:YES];
#endif
}
加载方法;我刚刚添加了if (self.aquariums == null)
检查,它可能已经解决了问题,但我很难确认,因为我无法重新创建问题:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
NSLog(@"applicationDidBecomeActive called");
if (self.aquariums == NULL) {
NSLog(@"aquariums null, loading file");
#ifdef LITE_VERSION
NSString *filePath = [self dataFilePathLite];
#else
NSString *filePath = [self dataFilePath];
#endif
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
self.aquariums = array;
[array release];
[self update21];
} else {
#ifdef LITE_VERSION
[self convertFileName];
#else
[self update20];
#endif
}
application.applicationIconBadgeNumber = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
aquaPlannerAppDelegate_iPad *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.rootView viewDidAppear:YES];
}
}
}
答案 0 :(得分:0)
在发布并且没有收到任何数据丢失报告后,问题肯定是
if (self.aquariums == NULL) {
所以人们记得,当应用程序从后台返回时,如果要重新加载数据,请先将其设置为null并释放
aquariums = NULL;
[aquariums release];