UITableViewCell imageView没有显示

adi*_*dit 6 iphone objective-c ipad ios afnetworking

所以我有以下代码:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

但是,我没有在单元格中看到imageView.我究竟做错了什么?

Hai*_*Kao 5

我也遇到了 SDImageCache 相同的问题。我的解决方案是放置一个具有您想要的帧大小的占位符图像。

 UIImage *placeholder = [UIImage imageNamed:@"some_image.png"];
 [cell.imageView setImage:placeholder];
 [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];
Run Code Online (Sandbox Code Playgroud)


Cli*_*udo 4

1) 使用 URL 设置图像不是 iOS 方法。这是习惯的事情,这可能就是问题所在。但在你发布之前,它对此无能为力。

2)我认为cell.imageView会忽略“setFrame”。我无法使用图像在任何表格单元格中使用它。它似乎总是默认为图像的宽度。

3) 通常,您可以使用 cell.imageView.image = your_Image 设置图像。ImageView 是只读的,并且 ImageView 框架可能是私有的。

4)我认为您需要创建一个自己的自定义单元。