我有资源:
Test.png
test1.jpg
tesT2.jpg
tEst3.jpg
我需要在
UIImageView
中显示这张图片。所以我写了以下代码:imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[myObject.filename stringByDeletingPathExtension] ofType:[myObject.filename pathExtension]]];
myObject
是我的模型中的实体。我从 XML 中获取 filename
,但在 XML 中,它的格式如下:
filename="test.png"
filename="test1.jpg"
filename="test3.jpg"
filename="test3.jpg"
因为我在 pathForResource 中搜索 @"test" ofType "png",所以我的图像是 (null),但需要使用 @"Test" ofType "png"。
我该如何在不重命名资源的情况下获取正确的资源?