iphone - 如何让UITableViewCell中的图片平滑滚动?

标签 iphone objective-c cocoa-touch uitableview

我正在将图像加载到 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/

相关文章:

ios - 三元运算符在 'if' 条件下没有任何内容

iphone - HTML 视频只能通过耳机播放声音 -iOS?

objective-c - 添加对象到 NSDictionary

ios - 与导航 Controller 的协议(protocol)

objective-c - iOS super 奇怪的问题, subview 没有我添加就添加了

iphone - 如何将本地视频文件嵌入到 Html 中以在 UIWebView 中播放?

iOS : Programmatically control the volume of Notification alert and sound theme

iphone - UIImageView 第一次显示时出现延迟

ios - iphone numberOfSectionsInTableView 消息发送到解除分配的实例

ios - addTarget 不适用于 iOS 中的 UIButtons, View 被遮盖