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];
}
上記のコードImageLoader
では、 のサブクラスですNSOperation
。操作数を確認しているうちに、操作を追加しているのにゼロになっています。私が間違いを犯した場合はお知らせください。私が行った間違いを取得していないため、操作カウントがゼロになっています。
キューのインスタンスを作成しましたが、それは一度だけ作成され、何度も作成する代わりに同じインスタンスを使用しています。操作を追加した後、1 つの操作があることを示していますが、別の操作を追加しようとすると、カウントがゼロになります。
RemoteImageDownloader
のサブクラスですUIImageView
。でそのインスタンスを作成しましたUIViewcontroller
。
私が実際に何をしているのかを簡単に理解できるようになることを願っています。
今、私はその行にコメントしました[self.opQueue setMaxConcurrentOperationCount:2];
。現在、操作カウントを取得しています。なぜそうなのか誰にも教えてもらえますか?