简体   繁体   English

无法通过TableView单元格中的解析显示imageView

[英]Can't display an imageView from parse in tableview cell

When the iOS app runs nothing shows up in the cells, the image is of type "file" in parse. 当iOS应用运行时,单元格中未显示任何内容,则该图像在解析中的类型为“文件”。 I don't use the storyboard for this so I cant change the class for the imageView to PFImageView. 我没有为此使用情节提要,因此无法将imageView的类更改为PFImageView。 What's missing? 缺少了什么?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
    static NSString *simpleTableIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    // Configure the cell
    PFFile *thumbnail = [object objectForKey:@"logo"];
    PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
    thumbnailImageView.image = [UIImage imageNamed:@"placeholder.png"];
    thumbnailImageView.file = thumbnail;
    [thumbnailImageView loadInBackground];

    cell.textLabel.text = [object objectForKey:@"name"];
    cell.detailTextLabel.textColor=[UIColor lightGrayColor];
    cell.backgroundColor = [UIColor clearColor];

    thumbnailImageView=[[PFImageView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
    [thumbnailImageView setBackgroundColor:[UIColor clearColor]];

    [cell.contentView addSubview:thumbnailImageView];

    return cell;
}

Thanks in advance! 提前致谢!

Do you actually need these 3 lines... 您实际上是否需要这3条线...

thumbnailImageView=[[PFImageView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
[thumbnailImageView setBackgroundColor:[UIColor clearColor]];

[cell.contentView addSubview:thumbnailImageView];

You are already casting your existing ImageView to a PFImageView... 您已经将现有的ImageView投射到PFImageView了...

PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];

Which in turn should be the image view in you table cell. 依次应该是表单元格中的图像视图。 Does loadInBakground work well with table cells though? loadInBakground是否可以与表格单元一起loadInBakground工作? You could hit issues where the row its getting the image for may have already been reused by another image 您可能会遇到以下问题:获取图像所在的行可能已被另一张图像重用

I think the reason you can't see the image is because you are loading it in the background and setting it before the data has been obtained from parse. 我认为看不到图像的原因是因为您正在将其加载到后台并在从解析获取数据之前进行设置。 Could you try something like this: 你可以尝试这样的事情:

// Set placeholder to show before image finishes loading
PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
thumbnailImageView.image = [UIImage imageNamed:@"placeholder.png"];

PFFile *thumbnail = [object objectForKey:@"logo"];
[thumbnailImageView setFile:thumbnail];
[thumbnailImageView loadInBackground:^(UIImage *image, NSError *error) {
    if (!error) {
        // Configure your image view in here            
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
        [imageView setBackgroundColor:[UIColor clearColor]];     
        [imageView setImage:image];
        [cell.contentView addSubview:imageView];
    }
}];

Try something along these lines. 尝试以下方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM