Skip to content

Commit b157ecb

Browse files
committed
Fixed threading bug in the myMixedTask demo.
1 parent fdd147f commit b157ecb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Demo/Classes/HudDemoViewController.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,13 @@ - (void)myMixedTask {
265265
HUD.mode = MBProgressHUDModeIndeterminate;
266266
HUD.labelText = @"Cleaning up";
267267
sleep(2);
268-
// The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
269-
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
270-
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
268+
// UIImageView is a UIKit class, we have to initialize it on the main thread
269+
__block UIImageView *imageView;
270+
dispatch_sync(dispatch_get_main_queue(), ^{
271+
UIImage *image = [UIImage imageNamed:@"37x-Checkmark.png"];
272+
imageView = [[UIImageView alloc] initWithImage:image];
273+
});
274+
HUD.customView = [imageView autorelease];
271275
HUD.mode = MBProgressHUDModeCustomView;
272276
HUD.labelText = @"Completed";
273277
sleep(2);

0 commit comments

Comments
 (0)