Bundles and file access

后端 未结 3 1073
南方客
南方客 2021-02-06 17:35

I\'ve adding a series of folders to my project (using the Add existing file option). This results in the folder contents being shown in Xcode as a blue folder.

The follo

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 18:37

    Okay, I figured out one way in code to get what I needed:

      NSString *dir = [NSString stringWithFormat:@"File-03/images", imageIndex];
      NSString *file = [NSString stringWithFormat:@"image-%02d", imageIndex]; 
      NSString *path = [[NSBundle mainBundle] pathForResource:file ofType:@"jpg" inDirectory:dir];
    
      return = [UIImage imageWithContentsOfFile:path];
    

    The trick was to inDirectory in the bundle call.

提交回复
热议问题