我有一個數組或URL指向圖像出現在服務器上。現在我想在滾動視圖中顯示每行4個圖像的圖像。我想使用NSOperationQueue和NSInvocationOperation異步下載圖像。我使用以下網址作爲參考:
http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation異步使用NSOperationQueue從網上加載多個圖像
但我不知道我將如何下載多個圖像。我是否必須使用多個NSInvocationOperation對象運行for循環並將其添加到NSOperationQueue對象?
我正在尋找任何指導來實現我的任務。
編輯: 我已經做以下,但NSOperationQueue不能調用NSInvocationOperation對象
NSOperationQueue *queue = [NSOperationQueue new];
for(int i = 0;i<rowcount;i++){
for(int j =0; j<4;j++){
UIButton *btnAlbum = [[UIButton alloc] initWithFrame:CGRectMake(x, y, 72, 72)];
[btnAlbum setBackgroundImage:[UIImage imageNamed:@"placeHolder.png"] forState:UIControlStateNormal];
btnAlbum.tag = count+100;
//[btnAlbum addTarget:self action:@selector(viewAlbum:) forControlEvents:UIControlEventTouchUpInside];
[scrlvw addSubview:btnAlbum];
//[btnAlbum release];
x = x + 80;
count++;
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadImage)
object:nil];
[queue addOperation:operation];
[operation release];
}
x = 0;
y = y +80;
}
感謝
潘卡
@Priya我在這裏結束了使用ASIHTTPRequest,但現在已經被棄用,現在可以使用Alamofire – pankaj 2017-05-27 10:06:53