谁能告诉我这段代码为什么有效:
..non-relevant previous code
[self readPlist:@"s_a.plist"];
}
}
- (void)readPlist: (NSString *)fileName{
NSString *bundleString = [[NSBundle mainBundle] bundlePath];
NSString *plistPath = [bundleString stringByAppendingPathComponent:fileName];
NSArray *arr = [NSArray arrayWithContentsOfFile:plistPath];
但是以下返回 nil?
[self readPlist:@"s_a.plist"];
}
}
- (void)readPlist: (NSString *)fileName{
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:fileName ofType:@"plist"];
NSArray *arr = [NSArray arrayWithContentsOfFile:plistPath];
对我来说,我似乎也在做同样的事情。我一直在寻找几个 SO 解决方案,但我就是想不通。
最佳答案
[self readPlist:@"s_a.plist"];
NSString *plistPath = [bundle pathForResource:fileName ofType:@"plist"];
您将 s_al.plist 作为文件名传递,因此该方法现在查找失败的 s_a.plist.plist
关于ios - 使用 nsbundle 读取 plist,在一种情况下它有效,而在几乎类似的情况下它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22386990/