Reputation: 1733
Any examples available that update UIImageView images dynamically at a high rate? These images are received on a IP connection in a NSThread. But they don't update when I do imageView.image = newImageRecd;
EDIT: All data is recd on main thread
Appreciate any help/pointers.
Upvotes: 0
Views: 802
Reputation: 1566
For iOS 4 and later, you can use Grand Central Dispatch (GCD) to load images on a background thread. Here's a link that explains this process fully:
The tutorial above provides this code:
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
dispatch_sync(dispatch_get_main_queue(), ^{
[[cell imageView] setImage:image];
[cell setNeedsLayout];
});
});
I've been using this myself to load images from a remote server, and it's working great.
Upvotes: 1
Reputation: 55334
UI updates need to be performed on the main thread. If you are running the connection on a different thread, use:
[self performSelectorOnMainThread:@selector(updateImageView:) withObject:newImageRecd waitUntilDone:FALSE];
where updateImageView:
is the method used to set the image view's image property:
-(void)updateImageView:(UIImage *)image
{
[self.imageView setImage:image];
}
Upvotes: 0