6

昨天我更新到最新的 iOS 版本,发现我的代码的一个关键部分无法正常工作。

// file is @"2/3/3-bottom-cen.png"
NSString *filePath = [[NSBundle mainBundle] pathForResource:file 
                                                         ofType:nil
                                                    inDirectory:@"VillageImages"];

此代码导致 filePath 的值为 nil,并且在 iOS7 上发生 - 该代码在以前的版本中正常工作。我搜索并没有找到任何最近的相关问题,所以我在这里询问任何方向。

4

1 回答 1

7

刚刚发现显然你不能在第一个参数中包含路径信息pathForResource:ofType:inDirectory:,只是文件名。

即 iOS7 的“工作”语法将是

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"3-bottom-cen.png" 
                                                         ofType:nil
                                                    inDirectory:@"VillageImages/2/3"];
于 2013-09-19T07:26:40.200 回答