views:

39

answers:

1

I have a simple UIView *myView which is set as follows

myView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]];

this takes the index r and gets that image, all works correctly in my two IBAction methods

-(IBAction) previousImageSelector{
if (r != 0)
    r = r - 1;
NSLog(@"r is%d",r);
myView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]];

}

I am currently allowing the user to save a picture to their favorites list with a title they input. This all works correctly, the name and index number of the image save to a mutableArray, The trouble comes when the user selects the table item.

My app retrieves the index of the image correctly, sets the index to that and then calls the

myView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]];

but for some reason this doesnt update the view, only the counter, and then if the user selects next or previous image the image after the current counter(the image which should have loaded) loads.

Is there a refresh method or a way to set it differently?

I dont understand why the same method works in the next and previous image IBActions, but not once a table row is selected.

advice please.

Regards

+1  A: 

In which method did you put your myView.image = [UIImage imageNamed... code?

Probably what you need to do is:

myView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]];
[myView setNeedsDisplay];

This tells the Core Animation to redraw the view with the current data (ie, the new image that you just set).

ryanprayogo
I put the code to set the image in the didSelectRowAtIndexPath: method and I tried the setNeedsDisplay method, it doesnt change anything. Regards
alJaree
What view did you update at the `didSelectRowAtIndexPath:` method? ie, what exactly is `myView` in your code?
ryanprayogo
myView is null when trying to access it in the other class.
alJaree