2012-05-22 19 views
6

Así que tenía el siguiente código:UITableViewCell imageView no mostrar

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *CellIdentifier = @"FriendsCell"; 

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)]; 
    [cell.textLabel setText:fd.name_]; 

    return cell; 
} 

Sin embargo, no estoy viendo la imageView en la célula. ¿Qué estoy haciendo mal?

+1

vamos a ver el método de -setImageWithURL – shabbirv

+1

junto con ver 'setImageWithURL:', ¿está seguro de que '** ** fd.imageUrl_' no es nulo? – WrightsCS

+0

sí, la url es válida y no es nula – adit

Respuesta

3

1) Conjunto de imágenes con el URL no es un método IOS. Es algo personalizado y ese puede ser el problema. Pero hasta que lo publique, no puede ayudar allí.

2) Creo que cell.imageView ignorará "setFrame". No puedo hacer que funcione en ninguna de las celdas de mi tabla usando una imagen. Siempre parece ajustarse por defecto al ancho de la imagen.

3) Normalmente configura la imagen usando cell.imageView.image = your_Image. ImageView está READONLY y probablemente el marco de ImageView es privado.

4) Creo que va a necesitar crear una celda personalizada propia.

2

que necesita para return cell al final del método

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *CellIdentifier = @"FriendsCell"; 

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)]; 
    [cell.textLabel setText:fd.name_]; 
    return cell; 
} 
+0

Lo hice en realidad ... Acabo de cortarlo – adit

4

Tuve el mismo problema con SDImageCache también. Mi solución es colocar una imagen de marcador de posición con el tamaño de fotograma que desee.

UIImage *placeholder = [UIImage imageNamed:@"some_image.png"]; 
[cell.imageView setImage:placeholder]; 
[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
3

El uso de un método con marcador de posición lo arreglará.

[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]]; 
Cuestiones relacionadas