我正在將圖像加載到我的UITableViewCell中,並且它變得波濤洶涌。我最多隻有5-10個細胞。如何使UITableViewCell中的圖像平滑滾動?
有沒有簡單的方法可以解決這個問題?
- (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;
}
的主要問題是在[NSData的dataWithContentsOfURL:...],直至下載完成,阻止你的應用程序。對我來說,解決這個問題的簡單而快速的方法是使用AFNetworking庫:在它的網站上,你可以找到一些有用的例子來說明如何下載圖像...... –