2012-05-22 4 views
6

donc j'ai eu le code suivant:UITableViewCell imageView ne montrant

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

Cependant, je ne suis pas voir la imageView dans la cellule. Qu'est-ce que je fais mal?

+1

nous allons voir votre méthode de -setImageWithURL – shabbirv

+1

En plus de voir 'setImageWithURL:', êtes-vous sûr ** 'fd.imageUrl_' ** est non nul? – WrightsCS

+0

oui l'url est valide et n'est pas nulle – adit

Répondre

3

1) Définir l'image avec l'URL n'est pas une méthode iOS. C'est quelque chose de personnalisé et c'est peut-être le problème. Mais jusqu'à ce que vous publiez cela ne peut pas aider là-bas.

2) Je pense que cell.imageView ignorera "setFrame". Je ne peux pas obtenir cela pour travailler dans l'une des cellules de mon tableau en utilisant une image. Il semble toujours par défaut à la largeur de l'image.

3) Généralement, vous définissez l'image en utilisant cell.imageView.image = your_Image. Le ImageView est READONLY et probablement le cadre ImageView est privé.

4) Je pense que vous aurez besoin de créer votre propre cellule personnalisée.

2

vous devez return cell à la fin de la méthode

- (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

Je l'ai fait en fait .. Je viens de le couper – adit

4

J'ai aussi le même problème avec SDImageCache. Ma solution consiste à mettre une image d'espace réservé avec la taille d'image que vous voulez.

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

L'utilisation d'une méthode avec un espace réservé le corrigera.

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