Domanda

Quindi ho avuto il seguente codice:

- (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.Cosa sto facendo male?

È stato utile?

Soluzione

1) Imposta immagine con URL non è un metodo iOS.È qualcosa di abitudine e potrebbe essere il problema.Ma finché non lo pubblichi non può aiutare lì.

2) Penso che cell.imageview ignorerà "setframe".Non riesco a far funzionare in nessuna delle mie cellule da tavolo usando un'immagine.Sembra sempre predefinito per larghezza dell'immagine.

3) In genere si imposta l'immagine utilizzando cell.imageview.image= your_image.L'imageview è readonly e probabilmente il telaio ImageView è privato.

4) Penso che avrai bisogno di creare una cella personalizzata.

Altri suggerimenti

Ho anche lo stesso problema con sdimagecache pure.La mia soluzione è quella di mettere un'immagine segnaposto con la dimensione del fotogramma che desideri.

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

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

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

È necessario generarecodicitagcode 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;
}
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top