Ios Can';我找不到我的护照,为什么?
我需要给我的plist写一个字符串,但是a找不到plist,为什么 in.h .m文件Ios Can';我找不到我的护照,为什么?,ios,objective-c,Ios,Objective C,我需要给我的plist写一个字符串,但是a找不到plist,为什么 in.h .m文件 #define DOCUMENTS [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] 在ViewDidLoad中 NSString *plistPath = [DOCUMENTS stringByAppendingPathComponent:@"Сamera.plist"]
#define DOCUMENTS [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
在ViewDidLoad中
NSString *plistPath = [DOCUMENTS stringByAppendingPathComponent:@"Сamera.plist"];
if([[NSFileManager defaultManager] fileExistsAtPath:plistPath])
{
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
cameras = [NSMutableDictionary dictionaryWithDictionary:[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:nil errorDescription:nil]];
}
//改为这样做:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *plistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Сamera.plist"];
//改为这样做:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *plistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Сamera.plist"];
确保您的目录包含plist文件
确保您的目录包含plist文件。通常将其设置为
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0]
,而不是使用lastObject。也许这与此有关…试着看看它是否在正确的位置您记得在Xcode中添加它吗?通常它设置为[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0]
,而不是使用lastObject。可能与此有关…尝试查看它是否位于正确的位置您是否记得将其添加到Xcode中?[NSPathStore2 objectAtIndex:]:未识别的选择器发送到实例0x76cda20 2013-08-14 20:03:19.145 EHControl[1802:c07]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[NSPathStore2对象索引:]:无法识别的选择器发送到实例0x76cda20'SIGABTATA在编辑它编译但仍然找不到后,它会找到其他plist,但不是my=/如果您在模拟器上测试,请按照以下步骤打开应用程序的沙盒:查找器->转到文件夹->~/library->应用程序支持->iPhone模拟器->6.1->应用程序->查找您的应用程序->记录文档并查看您的Camera.pLIst文件是否存在。[NSPathStore2 objectAtIndex:]:发送到实例0x76cda20 2013-08-14 20:03:19.145 EHControl[1802:c07]***由于未捕获的异常“NSInvalidArgumentException”,原因终止应用程序:-[NSPathStore2 objectAtIndex:]:无法识别的选择器发送到实例0x76cda20'SIGABTATA在编辑它编译但仍然找不到后,它会找到其他plist,但不是my=/如果您在模拟器上测试,请按照以下步骤打开应用程序的沙盒:查找器->转到文件夹->~/library->应用程序支持->iPhone模拟器->6.1->应用程序->查找您的应用程序->创建文档并查看您的Camera.pLIst文件是否存在。
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *docDirPath = [documentsDirectory stringByAppendingPathComponent:@"YourPlist.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath: docDirPath]) {
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"YourPlist" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath:docDirPath error:&error];
NSLog(@"plist is copied to Directory");
}