English 中文(简体)
Uitable ViewCell 图像View 没有显示
原标题:UITableViewCell imageView not showing

所以我有以下代码:

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

然而,我没有看到在牢房里看到图像View。我做错什么了?

最佳回答

1) 用 URL 设置图像不是 iOS 方法。 这是自定义的, 可能是问题所在 。 但在您公布图像前, 无法帮助 。

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

3) 您通常使用单元格. imageView. image = our_ image 设置图像。 图像View is READONLY, 很可能图像View 框架是私有的 。

4) 我认为你需要 创建一个自己的定制细胞。

问题回答

我对SDimageCache也有同样的问题。 我的解决方案是按您想要的框架大小设置一个占位符图像 。

 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 单元格

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




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签