Tanner
Tanner

Reputation: 133

UIImage initWithContentsOfFile doesn't work

I have question: I want to avoid [UIImage imageNamed:]. So i did:

UIImage *prodImg = [[UIImage alloc] initWithContentsOfFile:@"myimage.png"]; 
controller.productImg.image = prodImg;  
[prodImg release];

But now the image is not shown anymore.

Does anyone know how to get that to work?

Upvotes: 12

Views: 13630

Answers (1)

Devarshi
Devarshi

Reputation: 16758

The above code is not working because correct way to do it is-

NSString *thePath = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"jpeg"];
UIImage *prodImg = [UIImage imageWithContentsOfFile:thePath]; 
controller.productImg.image = prodImg;  
[prodImg release];

;)

Upvotes: 26

Related Questions