2012-05-22 23 views
6

Così ho avuto il seguente codice:UITableViewCell ImageView non mostrando

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

Tuttavia, non sto vedendo l'IMAGEVIEW nella cella. Che cosa sto facendo di sbagliato?

+1

vediamo il metodo -setImageWithURL – shabbirv

+1

Insieme a vedere 'setImageWithURL:', sei sicuro che ** 'fd.imageUrl_' ** non è pari a zero? – WrightsCS

+0

sì l'url è valido e non è nil – adit

risposta

3

1) Set Immagine con l'URL non è un metodo di iOS. È qualcosa di personalizzato e questo potrebbe essere il problema. Ma fino a quando non lo pubblichi non può aiutarti.

2) Penso che cell.imageView ignorerà "setFrame". Non riesco a farlo funzionare in nessuna delle mie celle di tabella utilizzando un'immagine. Sembra sempre di default alla larghezza dell'immagine.

3) In genere si imposta l'immagine utilizzando cell.imageView.image = your_Image. ImageView è READONLY e probabilmente il frame ImageView è privato.

4) Penso che sarà necessario creare una cella personalizzata personalizzata.

2

è necessario return cell alla fine del metodo

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

l'ho fatto in realtà .. l'ho appena interrotto – adit

4

Ho avuto lo stesso problema anche con SDImageCache. La mia soluzione è di inserire un'immagine segnaposto con la dimensione del fotogramma desiderata.

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

L'utilizzo di un metodo con segnaposto lo risolverà.

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