質問

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

- (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を見ていません。私は何を間違っていますか?

役に立ちましたか?

解決

1)URLを使って画像を設定するiOSメソッドではありません。それは注文であり、それが問題であるかもしれません。しかし、あなたがそれを公開するまでそこに助けることができない。

2)Cell.ImageViewは "SetFrame"を無視します。画像を使って私のテーブルセルのいずれかで働くことができません。それは常に画像の幅にデフォルトのようです。

3)通常、cell.imageview.image= your_imageを使用してイメージを設定します。ImageViewはreadonlyであり、おそらくimageViewフレームはプライベートです。

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

他のヒント

SDIMAGECACHACHASにも同じ問題を抱えています。私の解決策はあなたが望むフレームサイズでプレースホルダーイメージを置くことです。

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

プレースホルダーを使った方法の使用はそれを解決します。

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

メソッドの最後に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;
}
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top