UIImageView не работает в UITableViewCell - PullRequest
0 голосов
/ 17 ноября 2011

Я использую этот код для загрузки изображения в мой UITableView.

Но ничего не загружается, есть идеи, почему? Ссылка верна, когда я ее вижу.

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;
}

Ответы [ 2 ]

1 голос
/ 17 ноября 2011

Вы пробовали с:

cell.patientImage.image = image;

Конечно, вам не нужно создавать myImageView.

0 голосов
/ 17 ноября 2011

Попробуйте добавить проценты к вашей строке URL.

NSString *urlString = [[appointmentDictionaryTemp objectForKey:@"patient_small_photo_url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...