[英]UIImageView not working in UITableViewCell
I'm using this code to load an image into my UITableView. 我正在使用此代码将图像加载到我的UITableView中。
But nothing is loading, any ideas why? 但是什么都没有载入,有什么想法吗? The link is correct when I NSLog it.
当我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;
Update: 更新:
- (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;
}
Have you tried with: 您是否尝试过:
cell.patientImage.image = image;
Of course you don't need to create myImageView
. 当然,您无需创建
myImageView
。
尝试将转义百分比添加到您的URL字符串中。
NSString *urlString = [[appointmentDictionaryTemp objectForKey:@"patient_small_photo_url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.