gpt4 book ai didi

ios - 来自指针的 PFFile 抛出异常

转载 作者:行者123 更新时间:2023-11-29 02:59:29 25 4
gpt4 key购买 nike

我正在尝试使用解析从指针获取图像。我正在尝试从类中提取图像而不发出第二个请求。

这是代码:

PFFile * connectImageFile = [object objectForKey:@"prayerImage"];
connection.connectImage.file = connectImageFile;
[connection.connectImage loadInBackground];

第二行抛出以下异常:

-[PFObject url]: unrecognized selector sent to instance 0x16d4f480

我确信我正在使用 PFTableViewCell (它位于 PFTableViewController 中)并且我 connectImagePFImageViewer在代码和 Interface Builder 中它是链接的。我省略了最后两行并添加了: NSLog(@"%@", connectImageFile.url);出于调试目的,仍然出现错误:

-[PFObject url]: unrecognized selector sent to instance 0x14557680

显然这是一个不同的实例,但看似相同的问题......当我 NSLog 只是 connectImageFile然后我就得到:<prayers:W9SUTK3uL3:(null)>这是正确的 objectID...所以我完全不知道。

编辑:为了安全起见,我对图像进行了单独的查询,但仍然存在问题。当我尝试填充 PFImageView 时它没有崩溃但是当我尝试从PFObject获取url时确实崩溃了.这是我的代码:

PFObject * prayerImageObject = [object objectForKey:@"prayerImage"];
NSLog(@"%@", prayerImageObject.objectId);

PFQuery * query = [PFQuery queryWithClassName:@"prayers"];

[query whereKey:@"ObjectId" equalTo:prayerImageObject.objectId];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFFile * connectImageFile = [object objectForKey:@"prayerImage"];
connection.imageView.file = connectImageFile;

NSLog(@"%@", connectImageFile.url);

[connection.imageView loadInBackground];

}];

我的第一个NSLog给了我一个很好的objectId并且确实与我想要接收的正确图像相对应。我的第二个NSLog是抛出异常的地方(与整个 PFObject 处理非常相似,除了具有不同的十六进制值)。

编辑根据要求,这里是我的实现文件:

    //
// connectTableViewController.m
// Prayer
//
// Created by Evan Is Stupid on 12/29/13.
// Copyright (c) 2013 Evan Stoddard. All rights reserved.
//

#import "connectTableViewController.h"
#import "connectTableViewCell.h"
#import <Parse/Parse.h>

@interface connectTableViewController ()

@property (nonatomic, retain) connectTableViewCell * connection;

@end

@implementation connectTableViewController
@synthesize connection;

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

// Custom the table
// The className to query on
self.parseClassName = @"connections";

// 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 = 5;

}
return self;
}


- (void)viewDidLoad
{
[super viewDidLoad];
self.connection = [[connectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"connectionCell"];
}

- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];

}

- (void)objectsWillLoad {
[super objectsWillLoad];

}

- (PFQuery *)queryForTable {

PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query whereKey:@"username" equalTo:[PFUser currentUser]];

// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if ([self.objects count] == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}

return query;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

return [self loadTableViewObjects:object withTableView:tableView];

}

- (connectTableViewCell *)loadTableViewObjects:(PFObject *)object withTableView:(UITableView *)tableView{

connection = [tableView dequeueReusableCellWithIdentifier:@"connectionCell"];

PFObject * prayerImageObject = [object objectForKey:@"prayerImage"];
NSLog(@"%@", prayerImageObject.objectId);

PFQuery * query = [PFQuery queryWithClassName:@"prayers"];

[query whereKey:@"ObjectId" equalTo:prayerImageObject.objectId];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFFile * connectImageFile = [object objectForKey:@"prayerImage"];
connection.imageView.file = connectImageFile;

NSLog(@"%@", connectImageFile.url);

[connection.imageView loadInBackground];

}];

connection.connectTitle.text = @"Someone has prayed for you!";
return connection;

}

@end

最佳答案

如果您试图通过对象的指针获取对象内部的图像,则需要先调用fetch

所以,如果我理解你的问题是正确的,你应该尝试:

PFObject *object... 
[object fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error) {
// Now get the file
PFFile * connectImageFile = [object objectForKey:@"prayerImage"];
// continue your code
}
}];

更新:

这是适合我的代码。不幸的是,我不能像你想要的那样只通过一个请求来完成。为此,您之前必须已经获取了该对象。

    // This is the PFObject
PFObject *object = [PFObject objectWithoutDataWithClassName:@"SomeClass" objectId:@"id"];
// I needed to fetch the first object
[object fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
// Here, I get the second object, inside pointer column
PFObject *object2 = object[@"pointer"];
// Fetch again to get data
[object2 fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
// get PFFile in image column
PFFile * file = [object2 objectForKey:@"image"];
NSLog(@"url %@", file.url);
// Now continue code to assign image.
}];
}];

如果您查询有问题的对象,您可以包含具有指针的键,这样您将只使用一个请求。

关于ios - 来自指针的 PFFile 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23463921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com