我目前有一些問題,我的UITableView,這是第一次我把縮略圖在我的表視圖單元格,並整合NSThread加載縮略圖,所以,請與我裸露。由於NSThread,UITableViewCell的和圖像
我下載的數據和設置像往常一樣在細胞,倒是這次與NSThread。
首先,我會打電話給ASIHTTPRequest在我看來,做負載
然後在 - (空)requestFinished:(ASIHTTPRequest *)的要求,我將添加縮略圖的網址進入一個NSMutableArray
NSString *photoURLString = [NSString stringWithFormat:@"http://some.url.com/img/%@",[thearray objectForKey:@"tn_url"]];
[thumbNailURL addObject:(photoURLString)];
而且在的cellForRowAtIndexPath:我在哪裏設置的其他數據顯示,我會打電話給我的NSThread
[NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:self withObject:indexPath];
而且在我的LoadImage線程
- (void) loadImage: (NSIndexPath*) indexPath{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *iconURL = [thumbNailURL objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:iconURL];
UIImage *icon = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
cellImageView = [[UIImageView alloc] initWithFrame:CGRectMake(11.0, 6.0, 61.0, 50.0)];
[cellImageView setImage:icon];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.contentView performSelectorOnMainThread:@selector(addSubview:) withObject:cellImageView waitUntilDone:NO];
[pool drain];
}
的所有數據和圖像加載就好了,但如果我更快地上下滾動,應用程序會用以下錯誤掛
[1997:7a1f] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]' (0x31312d2f 0x345f50e3 0x3127d1b1 0x35aefc1d 0xf4dd 0x333ffb51 0x3347c67b 0x366af589 0x366b2310) terminate called throwing an exceptionProgram received signal: 「SIGABRT」.
這將是巨大的,如果如果我錯了,任何人都可以告訴我正確的配置,因爲過去3天我一直在嘗試不同的方式。非常感謝。
首先,非常感謝你的大力幫助,SDWebImage的作品非常棒!易於集成。 爲了涵蓋我在我的問題中遺漏了什麼,是的,我沒有檢查圖像是否存在,我猜它每次下載單元格時都會下載並導致崩潰(儘管我不確定應該在哪裏集成支票);我實際上有一個佔位符單元格設置,如果異步沒有完成,一旦完成,它會reloadData。所以一切都很好,直到NSThread的點。 – 2011-06-14 19:13:19