开发者

View wont update image(iphone app)

开发者 https://www.devze.com 2023-01-06 02:26 出处:网络
I have a simple UIView*myView which is set as follows myView.image = [UIImage imageNamed:[NSString stringWithFormat:@\"%d.png\", r]];

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 开发者_如何学JAVAthe 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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消