objective c - iOS: SDWebImageManager not caching image -
i'm creating slideshow using uiimageview
, , image links in array , while @ it, learned sdwebimagemanager
lets hit urls once , caches images later use.
but i'm monitoring in app 1st image cached, believe, 2nd image url being hit.
here's code:
- (void)viewdidload { [super viewdidload]; arry = [[nsmutablearray alloc] init]; [arry addobject:@"http://adjingo.2cimple.com/content/151/image/6291.jpg"]; [arry addobject:@"http://adjingo.2cimple.com/content/151/image/6290.jpg"]; nsurl *imageurl = [nsurl urlwithstring:[arry objectatindex:0]]; __block uiactivityindicatorview *activityindicator; __weak uiimageview *weakimageview = self.imageview; sdwebimagemanager *manager = [sdwebimagemanager sharedmanager]; [manager downloadimagewithurl:imageurl options:0 progress:^(nsinteger receivedsize, nsinteger expectedsize) { // progression tracking code if (!activityindicator) { [weakimageview addsubview:activityindicator = [uiactivityindicatorview.alloc initwithactivityindicatorstyle:uiactivityindicatorviewstylegray]]; //activityindicator.center = self.imageview.center; [activityindicator startanimating]; } } completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype, bool finished, nsurl *imageurl) { if (image) { // image [activityindicator removefromsuperview]; activityindicator = nil; [self.imageview setimage:image]; } }]; //timer slideshow images timer = [nstimer scheduledtimerwithtimeinterval: 5.0 target: self selector: @selector(handletimer:) userinfo: nil repeats: yes]; }
here's handletimer
code, reload image in image view, every 5 seconds:
-(void) handletimer: (nstimer *) timer { currentimage++; if ( currentimage >= arry.count ) currentimage = 0; __block uiactivityindicatorview *activityindicator; __weak uiimageview *weakimageview = self.imageview; sdwebimagemanager *manager = [sdwebimagemanager sharedmanager]; [manager downloadimagewithurl:imageurl options:0 progress:^(nsinteger receivedsize, nsinteger expectedsize) { // progression tracking code if (!activityindicator) { [weakimageview addsubview:activityindicator = [uiactivityindicatorview.alloc initwithactivityindicatorstyle:uiactivityindicatorviewstylegray]]; //activityindicator.center = self.imageview.center; [activityindicator startanimating]; } } completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype, bool finished, nsurl *imageurl) { if (image) { // image [activityindicator removefromsuperview]; activityindicator = nil; [self.imageview setimage:image]; } }]; }
here's monitor network usage:
please guide me if have used sdwebimagemanager
wrongly.
thanks
my mother language chinese,not english.maybe cannot express thought clearly,while try best tell idea.if confuse , feel sorry.
i cannot pod sdwebimage because country blocks google sometimes,so cannot reproduce scenarios.while still give advice may
first of all, gave little context.maybe can post more information member variables , properties.when copy code xcode.i need add them myself.
second,you mean when use
nsurl *imageurl = [nsurl urlwithstring:[arry objectatindex:1]];,
sdwebimage hits urls every time , not use cache urls? can image source nslog cachetype.
completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype, bool finished, nsurl *imageurl) { if (image) { nslog(@"%d",cachetype); [activityindicator removefromsuperview]; activityindicator = nil; [self.imageview setimage:image]; } }];`
sdimagecachetypenone means image comes network.
sdimagecachetypedisk means image comes disk.
sdimagecachetypememory means image comes memory.
third,because downloadwithurl:options:completed:
excuted not on main thread. doubt sequence same thought.
Comments
Post a Comment