-(NSString*)dataFilePath{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:@"ProperyList.plist"];
}
iDevice 无法从此路径加载数据,只有模拟器可以。
最佳答案
首先,NSLog
从此方法返回的 dataFilePath
值,然后检查您的文档目录中是否存在 plist 文件 (PropertyList.plist)。使用以下代码来检查这一点:
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath:dataFilePath];
您还必须确认您是否使用了正确的文件名。 iOS 设备区分大小写,而模拟器则不区分大小写。
关于iOS plist 无法从 plist 加载数据,但可以在模拟器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11138193/