Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage imageWithContentsOfFile correct pathForResource

I have resources:

Test.png
test1.jpg
tesT2.jpg
tEst3.jpg

I need to show this image in UIImageView. So I wrote:

imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[myObject.filename stringByDeletingPathExtension] ofType:[myObject.filename pathExtension]]];

myObject is entity in my model. I get filename from xml, but in xml it have format like:

filename="test.png"
filename="test1.jpg"
filename="test3.jpg"
filename="test3.jpg"

So my Image is (null) because in pathForResource I search @"test" ofType "png", but need @"Test" ofType"png".

How I can get correct resources without renaming them?

like image 691
user2545330 Avatar asked Dec 18 '25 13:12

user2545330


1 Answers

If you can't rename the source data (which you should do really), then you would need to use the file manager to get a list of all of the files available and then do a case insensitive filter to get the matching name and use that.

like image 175
Wain Avatar answered Dec 20 '25 05:12

Wain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!