我试图修改它,看看这里的其他选项和谷歌搜索一些东西,但似乎没有任何工作。NSKeyedArchiver工作在模拟器,但不是设备,iOS SDK
这就是我所拥有的,就像我说的那样,它在模拟器中完美工作,但不是设备,女巫运行iOS 5.x 我感谢所有的帮助。
NSFileManager *filemgr;
NSString *docsDir;
NSArray *dirPaths;
filemgr = [NSFileManager defaultManager];
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
//Build the path to the data file
datafilePath = [[NSString alloc] initWithString: [docsDir
stringByAppendingPathComponent: @"data.archive"]];
// NSString *localPath = @"Documents/data.archive";
// datafilePath = [NSHomeDirectory() stringByAppendingPathComponent:localPath];
// Check if the file already exists
if ([filemgr fileExistsAtPath: datafilePath])
{
NSMutableArray *dataArray;
// NSDictionary *stuff;
dataArray = [NSKeyedUnarchiver
unarchiveObjectWithFile: datafilePath];
for(int i=0; i< [dataArray count]; i++){
titlestring = [dataArray objectAtIndex:i ];
detailsstring = [dataArray objectAtIndex:++i];
// date = [dataArray objectAtIndex:2];
[tabledata addObject:titlestring];
[tablesubtitles addObject:detailsstring];
}
}
}
这是saveButton行动: 就像我说的,我在模拟器上工作得很好,只是没有做到在任何设备,一切都显示空白。
if (i == 0) {
// [userDefaults setObject:titlefield.text forKey: @"titlehomework"];
// [userDefaults setObject:detailstextfield.text forKey:@"detailshomework"];
NSMutableArray *contactArray;
contactArray = [NSKeyedUnarchiver
unarchiveObjectWithFile: datafilePath];
// contactArray = [[NSMutableArray alloc] init];
[contactArray addObject:titlefield.text];
[contactArray addObject:detailstextfield.text];
[NSKeyedArchiver archiveRootObject:
contactArray toFile:datafilePath];
// NSDictionary *stuff;
}
如果你确切地描述*什么*不起作用,这将是有帮助的。告诉我们你认为应该发生什么,实际发生了什么,以及到目前为止你已经尝试了什么。 – Caleb 2012-02-27 01:14:51
编码代码也是有帮助的。 – fbernardo 2012-02-27 01:30:08
好吧,我想我不创建文件,datafilePath也创建文件?将尽快编辑,但这基本上是我所有,我应该在委托中创建文件? – franklinexpress 2012-02-27 01:40:36