iosuiimageviewccsprite

How can CCSprite load ImageURL


UIImageView *imageView = [[UIImageView alloc] init];
[ImageViewHelper setImageURL:productInfo.ImageUrl forImageView:imageView];
CCSprite *imageSprite = [CCSprite spriteWithCGImage:imageView.image.CGImage key:productInfo.ImageUrl];

setImageURL: forImageView: is a multithreaded way, and when I perform to the third step, the imageView does not get loaded successfully, because it's done on a separate queue via multi-threading, but imageSprite needs the imageView.image to be valid.


Solution

  • If you are getting the data from a back ground thread, please try getting back onto the main queue while loading the image sprite:

    dispatch_sync(dispatch_get_main_queue(), ^{});