ios - 使用 nsbundle 读取 plist,在一种情况下它有效,而在几乎类似的情况下它不起作用

标签 ios objective-c

谁能告诉我这段代码为什么有效:

        ..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/

相关文章:

ios - 导航栏重叠信息

ios - Apple pay PKPaymentauthorizationViewController 在加载付款请求时总是返回 nil

objective-c - Objective-C 中的简单 http post 示例?

iphone - 试图了解iOS平台上的内存管理

iphone - 为什么这段 Objective C 代码会泄漏内存?

iphone - 循环和中断动画

ios - 将滑动手势从 UIView 转发到 UIScrollView

ios - NSTimer 中的 NSDate 格式化程序

ios - 适用于 iOS 7 的条码扫描 SDK?

ios - 在 UIImageView 上下动画 UIImage(就像它悬停一样)循环