I have the following code
NSString *myPath = [NSString stringWithFormat:@"../Documents/%@",@"bla.png"];
[imgView setImage:[UIImage imageNamed:myPath]]; // works fine
[self updateMyImage:[UIImage imageNamed:myPath]]; // loads another image as bla.png (works fine)
[imgView setImage:[UIImage imageNamed:myPath]]; // displays the old image, *not* the new one
The image is loaded in updateMyImage: (I open it (from the simulator's disk) and it is the "new" one)
but imgView displays the "old" one. I guess its a cache issue. Since the iOS has loaded the [UIImage imageNamed:@"bla.png"]
once, it thinks that this is the same one. How can I "flush" the cache and tell it to reload the image?
setImage: loads (as you corectly guess) from the cache. Look for it in the 'UIImage Class Reference' (on xcode's Organizer window)
Few lines down it gives you the answer: use the initWithContentsOfFile: method. So, after you change the image do this:
NSString *myAbsolutePath = [NSString stringWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0],@"bla.png"]];
UIImage *myImg = [[UIImage alloc] initWithContentsOfFile:myAbsolutePath];
[imgView setImage:myImg];
and now imgView will have the new image (as long as a img file exists at myAbsolutePath).