【发布时间】:2011-11-16 23:10:42
【问题描述】:
我正在使用此代码将图像加载到我的 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;
}
【问题讨论】:
-
您能否查看请求的响应,如果返回,您可能无法获取图像数据。
-
这个问题有很多代码,但我错过了关键部分:什么是'cell'类,它的'patientInage'是什么
-
猜测单元格为 Nil。编辑:没有看到它已经工作了
标签: iphone objective-c cocoa-touch uitableview uiimageview