Iphone 在iPod Touch上写入属性列表不起作用,但在模拟器中起作用
在我正在编写的应用程序中,我试图将一个幸运饼的财富列表写入一个属性列表。在模拟器中,这是预期的工作,一切都很好。在iPodtouch上,我看到的是上面所说的列表,很好,但它从不更新列表 使用模拟器更新属性列表和使用iPod Touch更新属性列表有什么区别吗Iphone 在iPod Touch上写入属性列表不起作用,但在模拟器中起作用,iphone,objective-c,cocoa-touch,ipod-touch,Iphone,Objective C,Cocoa Touch,Ipod Touch,在我正在编写的应用程序中,我试图将一个幸运饼的财富列表写入一个属性列表。在模拟器中,这是预期的工作,一切都很好。在iPodtouch上,我看到的是上面所说的列表,很好,但它从不更新列表 使用模拟器更新属性列表和使用iPod Touch更新属性列表有什么区别吗 if(indexEdit == [data count]) { NSString *temp = [NSString stringWithFormat:@"%@", textField.text];
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];
}
我认为您的应用程序包被认为几乎是只读的。如果要编写文件,应将其放入“Documents”文件夹中,如:
NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSMutableString *savePath = [NSMutableString stringWithString:[savePaths objectAtIndex:0]];
[savePath appendString:@"/Fortunes"];
// blah blah
[plistData writeToFile:savePath atomically:YES];
我认为您的应用程序包被认为几乎是只读的。如果要编写文件,应将其放入“Documents”文件夹中,如:
NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSMutableString *savePath = [NSMutableString stringWithString:[savePaths objectAtIndex:0]];
[savePath appendString:@"/Fortunes"];
// blah blah
[plistData writeToFile:savePath atomically:YES];
我不得不说是财富,而不是财富,但它起作用了。谢谢。我会这样做:NSString*filename=[savePathstringByAppendingPathComponent:@“Fortunes.plist”];相反,这样你就不用担心了,好的,本尼。为我辩护,我第一次开始学习Cocoa时就写了这段代码!我不得不说是财富,而不是财富,但它起作用了。谢谢。我会这样做:NSString*filename=[savePathstringByAppendingPathComponent:@“Fortunes.plist”];相反,这样你就不用担心了,好的,本尼。为我辩护,我第一次开始学习Cocoa时就写了这段代码!