1

在我正在编写的应用程序中,我试图将幸运饼干的财富列表写入属性列表。在模拟器中,这按预期工作,一切都很好。在 iPod Touch 上,我可以很好地从所述列表中读取,但它从不更新列表。

使用模拟器更新属性列表和使用 iPod Touch 更新属性列表有什么区别吗?

    if(indexEdit == [data count])
    {
        NSString *temp = [NSString stringWithFormat:@"%@", textField.text];
        [self.data addObject:temp];
    }
    else
    {
        NSString *temp = [NSString stringWithFormat:@"%@", textField.text];
        [data replaceObjectAtIndex:indexEdit withObject:temp];
    }
    NSString *errorDesc;
    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Fortunes"  ofType:@"plist"];
    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:data format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
    if (plistData)
    {
        [plistData writeToFile:bundlePath atomically:YES];
    }
    else 
    {
        NSLog(errorDesc);
        [errorDesc release];
    }
4

1 回答 1

4

我认为您的应用程序包被认为是只读的。如果你想写一个文件,你应该把它放在“Documents”文件夹中,比如:

NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSMutableString *savePath = [NSMutableString stringWithString:[savePaths objectAtIndex:0]];
[savePath appendString:@"/Fortunes"];

// blah blah

[plistData writeToFile:savePath atomically:YES];
于 2009-06-09T14:46:37.220 回答