PFQueryTableViewController在使用Storyboard时不显示图像

时间:2014-10-29 01:58:53

标签: parse-platform

我已经做了很多研究,弄清楚为什么会发生这种情况并尝试了很多事情而没有成功。 我正在使用PFQueryTableViewController从parse.com提取数据。我正在使用Storyboard。我没有使用自定义表格视图单元格,只使用常规PFTableViewCell。

从解析中提取数据,单元格中的文本按预期显示,但不显示任何图像。甚至没有显示占位符图像。调试时,我可以看到PFTableViewCell的_remoteImageView属性为零。我认为这是因为Storyboard中的原型单元没有图像视图。但原型单元与Custom Class中的PFTableViewCell绑定。

我尝试过的事情:

  • 通过initWithCoder初始化我的自定义TableViewController(从PFQueryTableViewController派生)(而不是从initWithStyle)。没用。
  • 使用cellForRowAtIndexPath中的图像将cell.imageView文件设置为PFFile后调用[cell.imageView loadInBackground]。没用。

如果我不使用dequeueReusableCellWithIdentifier:cellIdentifier并使用initWithStyle直接实例化该单元:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier,则显示图像!!但是segue不起作用(它没有进入详细视图)。

请帮忙! 请参阅以下代码:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if (self)
    {
        // The className to query on
        self.parseClassName = @"RestaurantType";

        // The key of the PFObject to display in the label of the default cell style
        self.textKey = @"text";

       // Uncomment the following line to specify the key of a PFFile on the PFObject to display in the imageView of the default cell style
        self.imageKey = @"image";

       // Whether the built-in pull-to-refresh is enabled
       self.pullToRefreshEnabled = YES;

       // Whether the built-in pagination is enabled
       self.paginationEnabled = YES;

       // The number of objects to show per page
       self.objectsPerPage = 25;
    }

    return self;
}

- (PFQuery *)queryForTable
{
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    if (self.objects.count == 0)
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;

    [query orderByAscending:@"type"];

    return query;
 }

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

    PFTableViewCell* cell = (PFTableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (!cell)
        cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

    cell.textLabel.text = object[@"type"];
    PFFile *thumbnail = object[@"image"];
    cell.imageView.image = [UIImage imageNamed:@"AppIcon58x58.png"];
    cell.imageView.file = thumbnail;

    return cell;
}

0 个答案:

没有答案