2012-05-22 21 views
6

Więc miałem następujący kod:UITableViewCell ImageView nie pokazując

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

Jednak nie jestem widząc ImageView w komórce. Co ja robię źle?

+1

zobaczmy metoda -setImageWithURL – shabbirv

+1

wraz z widząc 'setImageWithURL:', jesteś pewien, że ** 'fd.imageUrl_' ** nie jest zerowa? – WrightsCS

+0

tak, adres URL jest ważny i nie jest zerowy – adit

Odpowiedz

3

1) Ustaw obraz z adresu URL nie jest metodą iOS. Jest to coś niestandardowego i może to być problem. Ale dopóki go nie opublikujesz, nic na to nie poradzę.

2) Myślę, że cell.imageView zignoruje "setFrame". Nie mogę tego zrobić w żadnej z moich komórek tabeli za pomocą obrazu. Wydaje się domyślnie szerokość obrazu.

3) Zazwyczaj można ustawić obraz za pomocą komórki.imageView.image = your_Image. ImageView jest READONLY i prawdopodobnie ramka ImageView jest prywatna.

4) Myślę, że będziesz potrzebować stworzyć własną komórkę.

2

trzeba return cell na końcu metody

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

Zrobiłem to w rzeczywistości .. Po prostu to odciąłem – adit

4

Mam ten sam problem z SDImageCache, jak również. Moim rozwiązaniem jest umieszczenie obrazu zastępczego o żądanym rozmiarze ramki.

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

Użycie metody z symbolem zastępczym spowoduje jej usunięcie.

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