0
votes

I'm populating the animationImages field of my UIImageview via NSArray arrayWithObjects. When I put objects in the array via UIImage imageNamed: the UIImageview animates as expected. However when I put objects in the array via UIImage alloc initWithContentsOfFile I don't see the animated images (I just see the default image I pass to initWithImage for the UIImageview). Any ideas?

Cheers!

1

1 Answers

2
votes

That is because imageNamed: and initWithContentsOfFile: both look in different directories. imageNamed: looks in your bundle directory, initWithContentsOfFile: does not.

If you have code like this:

NSString *file = @"image.png";
UIImage *image = [UIImage imageNamed:file];

But you want to use initWithContentsOfFile:, you should use this code:

NSString *file = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:file];