我正在使用此代码将图像加载到我的UITableView中。
但是什么都没有加载,任何想法为什么?我在NSLog时链接是正确的。
NSString *temp = [appointmentDictionaryTemp objectForKey:@"patient_small_photo_url"];
NSData * imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:temp]];
UIImage * image = [UIImage imageWithData:imageData];
UIImageView * myImageView = [[UIImageView alloc] initWithImage:image];
cell.patientImage = myImageView;
更新
- (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;
}
答案 0 :(得分:1)
您是否尝试过:
cell.patientImage.image = image;
当然,您不需要创建myImageView
。
答案 1 :(得分:0)
尝试将百分比转义添加到您的网址字符串。
NSString *urlString = [[appointmentDictionaryTemp objectForKey:@"patient_small_photo_url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];