का उपयोग कर लोड हो रहा है मैं वर्तमान में फ़्लिकर फोटो (सीएस 1 9 3 पी आईओएस स्टैनफोर्ड, असाइनमेंट 5) की यूआईटीबल व्यू सूची लोड करने की कोशिश कर रहा हूं। यूआई अवरुद्ध करने से बचने के लिए, मैंने प्रत्येक सेल के थंबनेल डाउनलोड को एक अलग कतार में स्थगित कर दिया है (लेकिन यूआई को मुख्य कतार में वापस अपडेट करें)। यह कोड छवियों को अतुल्यकालिक रूप से लोड नहीं करता है, हालांकि एक बार जब मैं UITableViewCell पंक्ति पर क्लिक करता हूं तो थंबनेल जोड़ता है। (नीचे स्क्रीनशॉट देखें)। कोई विचार क्या मैं गलत कर रहा हूँ?असीमित यूआईटीबल व्यूसेल छवि जीसीडी
पीएस: मैंने पहले से ही कुछ अन्य स्टैक ओवरफ्लो प्रश्नों में देखा है & ऐप्पल के LazyTableImages उदाहरण, लेकिन मुझे विश्वास है कि वांछित परिणाम प्राप्त करने का यह सबसे साफ तरीका है।
धन्यवाद!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Photo List Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell
NSDictionary *photo = [self.photoList objectAtIndex:indexPath.row];
if (photo != nil) {
if ([[photo objectForKey:@"title"] length] > 0) {
cell.textLabel.text = [photo objectForKey:@"title"];
} else if ([[[photo objectForKey:@"description"] objectForKey:@"_content"] length] > 0) {
cell.textLabel.text = [[photo objectForKey:@"description"] objectForKey:@"_content"];
} else {
cell.textLabel.text = @"Unknown";
}
}
cell.imageView.image = [[UIImage alloc] initWithCIImage:nil];
// Fetch using GCD
dispatch_queue_t downloadThumbnailQueue = dispatch_queue_create("Get Photo Thumbnail", NULL);
dispatch_async(downloadThumbnailQueue, ^{
UIImage *image = [self getTopPlacePhotoThumbnail:photo];
dispatch_async(dispatch_get_main_queue(), ^{
if ([self.tableView.visibleCells containsObject:cell]) {
[cell.imageView setImage:image];
}
});
});
dispatch_release(downloadThumbnailQueue);
return cell;
}
पंक्ति
अद्यतन चयन करने के बाद एक पंक्ति
क्लिक करने से पहले:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Photo List Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell
NSDictionary *photo = [self.photoList objectAtIndex:indexPath.row];
if (photo != nil) {
if ([[photo objectForKey:@"title"] length] > 0) {
cell.textLabel.text = [photo objectForKey:@"title"];
} else if ([[[photo objectForKey:@"description"] objectForKey:@"_content"] length] > 0) {
cell.textLabel.text = [[photo objectForKey:@"description"] objectForKey:@"_content"];
} else {
cell.textLabel.text = @"Unknown";
}
}
cell.imageView.image = [[UIImage alloc] initWithCIImage:nil];
// Fetch using GCD
dispatch_queue_t downloadThumbnailQueue = dispatch_queue_create("Get Photo Thumbnail", NULL);
dispatch_async(downloadThumbnailQueue, ^{
UIImage *image = [self getTopPlacePhotoThumbnail:photo];
dispatch_async(dispatch_get_main_queue(), ^{
UITableViewCell *cellToUpdate = [self.tableView cellForRowAtIndexPath:indexPath]; // create a copy of the cell to avoid keeping a strong pointer to "cell" since that one may have been reused by the time the block is ready to update it.
if (cellToUpdate != nil) {
[cellToUpdate.imageView setImage:image];
[cellToUpdate setNeedsLayout];
}
});
});
dispatch_release(downloadThumbnailQueue);
return cell;
}
अरे, यह बजाय पर वस्तु समानता के लिए जाँच की पूरी तरह से विषय बंद है, लेकिन सोच ब्लॉक के अंदर आप मुख्य थ्रेड को भेजें, 'सेल', जांचें कि 'इंडेक्सपाथ' पर कोई सेल मौजूद है या नहीं? –
मैंने अभी यह कोशिश की: यदि ([self.tableView cellForRowAtIndexPath: indexPath]! = Nil) {... आदि} और यह ठीक काम करता है। क्या यह आपके मन में था? – sybohy
दाएं, और सीधे अपने ब्लॉक में 'cell.imageView' का उपयोग नहीं करते बल्कि 'indexPath' पर सेल को पकड़कर और इसके छवि दृश्य का उपयोग करके। मुझे लगता है कि यदि आप 'सेल' का उपयोग सीधे अपने मुख्य थ्रेड ब्लॉक के अंदर स्कॉप्ड करते हैं तो आप सेल पुन: उपयोग के साथ समस्याओं में भाग ले सकते हैं। –