7

だから私は次のコードを持っていました:

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

ただし、セルに imageView が表示されません。私は何を間違っていますか?

4

4 に答える 4

5

SDImageCacheでも同じ問題が発生しました。私の解決策は、希望するフレームサイズのプレースホルダー画像を配置することです。

 UIImage *placeholder = [UIImage imageNamed:@"some_image.png"];
 [cell.imageView setImage:placeholder];
 [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];
于 2012-06-11T14:06:11.917 に答える
4

1)URLで画像を設定するのはiOSの方法ではありません。それは習慣的なものであり、それが問題になる可能性があります。しかし、あなたが公開するまで、それはそこでは役に立ちません。

2)cell.imageViewは「setFrame」を無視すると思います。画像を使用して、どのテーブルセルでもそれを機能させることができません。デフォルトでは常に画像の幅になっているようです。

3)通常、cell.imageView.image=your_Imageを使用して画像を設定します。ImageViewは読み取り専用であり、おそらくImageViewフレームはプライベートです。

4)独自のカスタムセルを作成する必要があると思います。

于 2012-05-22T23:03:45.860 に答える
3

プレースホルダー付きのメソッドを使用すると修正されます。

[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]];
于 2013-06-30T07:02:28.880 に答える
2

return cellメソッドの最後に必要です

- (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;
}
于 2012-05-22T20:12:59.510 に答える