Reputation: 53
I have a Question regarding the UIImageView. I have a ObjectiveC-Class that contains a UIImageView and receive a callback from a delegate. From the delegate I get the UIImage that I want to insert to my UIImageView. But when I set the image it won't be shown.
@interface MyViewController ()
@property(nonatomic,strong) UIImageView* myImageView;
@implementation MyViewController
-(void) viewDidLoad
{
[super viewDidLoad];
self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,400,400)];
[self.view addSubview:self.myImageView];
-(void)frameworkService:(FrameworkService *)frameworkService
callbackfromDelegate:(UIImage*) myImage
{
self.myImageView.image = myImage;
}
}
Upvotes: 1
Views: 76
Reputation: 9522
If the callback is not on the main thread, UI won't update. But dispatch_async is unnecessary, just call:
[self.myImageView performSelectorOnMainThread:setImage: withObject:myImage waitUntilDone:NO];
Upvotes: 0
Reputation: 1038
You can only update the UI from the main thread:
dispatch_async(dispatch_get_main_queue(), ^{
... update here your ui ..
});
Upvotes: 2