首先看TableView擷取cell執行個體的方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
涉及Cell執行個體化的代碼:
PostCell *cell = (PostCell * (! NSArray *objects = [[NSBundle mainBundle] loadNibNamed: (NSObject *o ([o isKindOfClass:[PostCell = (PostCell **singleTap = cell.img.image = [UIImage imageNamed:*p = ([cell.img.gestureRecognizers count] > *tap = (UITap *)[cell.img.gestureRecognizers objectAtIndex: tap.tag == self.catalog <= ? : == [UIFont boldSystemFontOfSize:= [NSString stringWithFormat:= [NSString stringWithFormat: cell.img.image = ([p.img isEqualToString:= [UIImage imageNamed: NSData * imageData === IconDownloader *downloader = [imageDownloadsInProgress objectForKey:[NSString stringWithFormat: (downloader == ImgRecord *record = [ImgRecord = cell;
下一步,startIconDownload: forIndexPath:中的實現,簡要而言,就是做以下幾件事:
1. 執行個體化IconDownloader,並將其set到imageDownloadsInProgress中
2. iconDownloader的執行個體則使用
NSURLConnection *conn =:self];
進行非同步請求
3. 當conn執行完畢,執行它的delegate - IconDownloader的finish方法,在這個方法中緩衝image
4. finish方法中,調用delegate - PostView,將ImageData通過UIImagePNGRepresentation渲染為image(png) data,並調用[tablePosts reloadData]
這裡,值得商榷的是:每一張圖片載入完畢都調用一次reloadData的方式是否是最優?