ios - Not getting Operation Count for Operation Queue -
remoteimagedownloader *imgview = (remoteimagedownloader*)[cell viewwithtag:1]; if (imgview == nil) { imgview = [[remoteimagedownloader alloc] initwithframe:cgrectmake(0.0, 0.0, 50.0, cell.frame.size.height)]; imgview.tag = 1; [cell.contentview addsubview:imgview]; } imgview.image = nil; imgview.backgroundcolor = [uicolor graycolor]; imgview.opqueue = self.opqueue; //[imgview performselector:@selector(downloadremoteimageforurl:withcachingoption:) withobject:[_marrimgurl objectatindex:indexpath.row]]; if ([self checkdocdirectoryforfilename:[[_marrimgurl objectatindex:indexpath.row] lastpathcomponent]]) { [imgview setimage:[uiimage imagewithdata:[self checkdocdirectoryforfilename:[[_marrimgurl objectatindex:indexpath.row] lastpathcomponent]]]]; } else { [imgview downloadremoteimageforurl:[_marrimgurl objectatindex:indexpath.row] withcachingoption:nsurlrequestreloadrevalidatingcachedata isneedtosaveindocumentdirectory:yes]; } -(void)downloadremoteimageforurl:(nsstring*)strurl withcachingoption:(nsurlrequestcachepolicy)urlcachepolicy isneedtosaveindocumentdirectory:(bool)isneedsave { imageloader *subcategoryimgloader = [[[imageloader alloc] initwithurl:[nsurl urlwithstring:strurl]] autorelease]; subcategoryimgloader.target = self; subcategoryimgloader.didfinishselector = @selector(imagedownloaddidfinishwithdata:andoperation:); subcategoryimgloader.didfailselector = @selector(imagedownloadfailedwitherrordesc:andoperation:); [self.opqueue setmaxconcurrentoperationcount:2]; if ([self.opqueue operationcount] > 0) { nsoperation *lastoperation = [[self.opqueue operations] lastobject]; [subcategoryimgloader adddependency:lastoperation]; } [self.opqueue addoperation:subcategoryimgloader]; if (_actindicatorview) { [_actindicatorview removefromsuperview], _actindicatorview = nil; } _actindicatorview = [[uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylewhitelarge]; _actindicatorview.tag = 100; _actindicatorview.center = self.center; [self addsubview:_actindicatorview]; [_actindicatorview startanimating]; } in above code imageloader subclass of nsoperation. while i'm checking operation count, i'm getting 0 though i'm adding operations it. please let me know if i've done mistakes. i'm not getting mistakes i've done i'm getting 0 operation count.
i have created instance of queue , created once , i'm using same instance instead of creating again , again. after adding operation showing has 1 operation while i'm going add 1 i'm getting 0 count.
remoteimagedownloader subclass of uiimageview. have created instance in uiviewcontroller.
hope easy understand i' doing actually.
now commented line [self.opqueue setmaxconcurrentoperationcount:2];. getting operation count. can tell me why so?
the common reason
"i sending message x property y of object returns 0 , shouldn't"
is haven't set value property. i.e. in case self.opqueue nil.
edit we have eliminated above problem. however, below still relevant.
having said that, have race condition since operation count may change between test being greater 0 , adding dependency (e.g. if operation finishes).
you should this:
nsoperation* lastop = [[self.opqueue operations] lastobject]; if (lastop != nil) { [subcategoryimgloader adddependency:lastop]; } the documentation operationcount contains
the value returned method reflects instantaneous number of objects in queue , changes operations completed. result, time use returned value, actual number of operations may different. you should therefore use value approximate guidance , should not rely on object enumerations or other precise calculations.
(my bold)
i suspect happening when set max operations 2 that, time code second time, there no operations left on queue.
Comments
Post a Comment