How to Use SDWebImageManager in CCLayer

Source: Internet
Author: User
How to Use SDWebImageManager in CCLayer
1. In the header file

# Import "SDWebImageManager. h"

CCLayer must be implemented in the class definition

SDWebImageManagerDelegate.

Define and create

UIImageView * m_headImage;

2. Start downloading Avatar

- (void) upDateUserAvatar:(std::string) strAvatar{    if (strAvatar.length()<=0)     {        return  ;    }        NSString  * nsStrAvatar=[NSString  stringWithCString:strAvatar.c_str() encoding:NSUTF8StringEncoding];                if ([nsStrAvatar length] != 0)     {        SDWebImageManager* wim = [SDWebImageManager sharedManager];        [wim cancelForDelegate:self];        NSURL* url = [NSURL URLWithString:nsStrAvatar];        UIImage* cachedImage = [wim imageWithURL:url];        if (cachedImage)         {            m_headImage.image=cachedImage;        }         else         {            [wim downloadWithURL:url delegate:self];        }}}

3. Pair
SDWebImageManagerDelegate implementation code

//SDWebImageManagerDelegate  delegate  implement- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image{    UNUSED(imageManager);        m_headImage.image=image;}- (void)webImageManager:(SDWebImageManager *)imageManager didFailWithError:(NSError *)error{    UNUSED(imageManager);    UNUSED(error);}

4. Cancel download in OnExit

-(Void) onExit {// cancel the download request submitted by self [[SDWebImageManager sharedManager] cancelForDelegate: self]; [super onExit];}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.