In loadDidLoad controller call method with thread, like that:
- (void)viewDidLoad {
[super viewDidLoad];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadImages) object:nil];
[self.operationQueue addOperation:operation];
[operation release];
}
loadImages method downloading image and show it:
- (void) loadImages {
@synchronized (self) {
// download image...
// ...
// and next:
UIImageView *imageView = [imageViews objectAtIndex:currentImageIndex];
[imageView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
[imageView performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageWithData:imageData] waitUntilDone:YES];
}
//...
}
that work if show view first time, next time i must rotate iphone to show images.
why view doesn’t redraw?
i tried this code according to advices:
// imageButton is a UIView with button, image and label
NSData *imageData = [[HttpClient sharedInstance] getResourceWithCache:thumbPath];
[imageButton performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageWithData:imageData] waitUntilDone:YES];
[imageButton performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
[imageButton drawRect:imageButton.frame];
but do not work.
your problem is in the line
[imageView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];You would need to call setNeedsDisplay in self.view and not on self, as thats a method for UIView and not UIViewController.
Double check this by subclassing your view and putting a break point in drawRect: , as setNeedsDisplay must call drawRect.