该应用程序会将 NSMutableArray 保存到没有问题的存档中,但是一旦我尝试将 NSMutableArray 重新加载到新的 NSMutableArray @ viewDidLoad 中,应用程序就会崩溃。我在代码末尾放置了一个断点,其中“tempArray = [unarchiver decodeObjectForKey:kDataKey46];” 并且 tempArray 正在加载存档数组,但是当我通过“for”循环时 @“[poolListData addObject:testTemp];” “poolListData”不保存来自“tempArray”的数据。另外,如果我没有使用断点,只是让应用程序尝试加载,应用程序将崩溃......你们怎么看?
感谢您的时间!杰夫
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
field1.text = [unarchiver decodeObjectForKey:kDataKey1];
// snip another bunch of fields
field37.text = [unarchiver decodeObjectForKey:kDataKey37];
soundOn = [unarchiver decodeBoolForKey:kDataKey38];
soundVolumeSlider.value = [unarchiver decodeDoubleForKey:kDataKey39];
soundVolumeValue = [unarchiver decodeDoubleForKey:kDataKey39];
tempArray = [unarchiver decodeObjectForKey:kDataKey46];
[unarchiver finishDecoding];
for(int i = 0; i < [tempArray count]; i++)
{
NSData *testTemp = 0;
//NSString *temp = [tempArray objectAtIndex:i];
testTemp = [tempArray objectAtIndex:i];
[poolListData addObject:testTemp];
//[poolListData addObjectsFromArray:tempArray];
}
/*
firstNameTextField.text = field1.text;
lastNameTextField.text = field2.text;
adressTextField.text = field3.text;
emailTextField.text = field4.text;
*/
[tempArray release];
[unarchiver release];
[data release];
}