我正在将图像加载到 UITableViewCell 中,但它变得不稳定。我最多只有大约 5-10 个细胞。
有什么简单的方法可以解决这个问题吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"appointmentCell";
AppointmentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *appointmentDictionaryTemp = [self.appointmentArray objectAtIndex:indexPath.row];
cell.patientNameLabel.text = [appointmentDictionaryTemp objectForKey:@"patient"];
cell.appointmentTimeLabel.text = [appointmentDictionaryTemp objectForKey:@"scheduled_time"];
NSString *urlString = [[appointmentDictionaryTemp objectForKey:@"patient_small_photo_url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData * imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
UIImage * image = [UIImage imageWithData:imageData];
cell.patientImage.image = image;
return cell;
}
最佳答案
dataWithContentsOfURL:
是你的罪魁祸首。它在应用程序的主 UI 线程上执行同步(阻塞)网络请求,导致 TableView 在下载图像时锁定。
该解决方案涉及的内容要复杂得多,它涉及使用 NSURLConnection(或其他一些第 3 方库)异步下载数据,从而允许 UI 在下载图像时保持响应。 This是一个很好的引用资源。
关于iphone - 如何让UITableViewCell中的图片平滑滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8160223/