Objective c 如何在Xcode中获取PNG名称而不是整个目录路径?

Objective c 如何在Xcode中获取PNG名称而不是整个目录路径?,objective-c,xcode,png,filenames,nsbundle,Objective C,Xcode,Png,Filenames,Nsbundle,所以我在我的“支持文件”Xcode项目中有一个PNG列表。我这样做是为了访问所有扩展名为PNG的文件: NSArray *pngFilePaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@""]; NSLog(@"PNG:%@", pngFilePaths); 打印出这个: "/Users/John/Library/Application Support/iPhone Simulator/5.1/

所以我在我的“支持文件”Xcode项目中有一个PNG列表。我这样做是为了访问所有扩展名为PNG的文件:

NSArray *pngFilePaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@""];
NSLog(@"PNG:%@", pngFilePaths);
打印出这个:

"/Users/John/Library/Application Support/iPhone Simulator/5.1/Applications/123456-1234-1234-1234-B123412341234/MyPNGProject.app/UI_daily_time.png"
但是,我只想要PNG名称“UI_daily_time”,而不是整个路径。因此,我刚刚添加了上面的目录,以便使用以下内容访问png:

NSArray *pngFilePaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"/Users/John/Library/Application Support/iPhone Simulator/5.1/Applications/123456-1234-1234-1234-B123412341234/MyPNGProject.app/"];
NSLog(@"PNG:%@", pngFilePaths);

但是pngfilepath现在是空的,我猜我给它的“inDirectory”路径是错误的,但我不知道为什么。非常感谢您的帮助,提前谢谢

获得完整路径后,使用stringByDeletingPathExtension删除扩展,然后使用lastPathComponent仅获取名称:

NSString *pngFilePath = [pingFilePaths objectAtIndex:0];
NSString *pngName = [[pngFilePath stringByDeletingPathExtension] lastPathComponent];