- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个名为 PFGiveItem 的 PFObject 子类。
@interface PFGiveItem : PFObject <PFSubclassing>
+(NSString *)parseClassName;
@property (strong, nonatomic) NSString *giveItemName;
@property (strong, nonatomic) UIImage *giveItemImage;
@end
当我尝试查询已保存到 Parse 的图像,然后将图像保存到我的每个 GiveItems 时,出现错误。这是一个更大的循环的一部分,它包括它自己的 PFQuery;我只是隔离这部分以保持简单,因为它的其余部分都有效。
PFQuery *queryForRelatedImages = [PFQuery queryWithClassName:@"giveItemPhoto"];
[queryForRelatedImages whereKey:@"objectId" equalTo:@"pAwHU2e7aw"];
[queryForRelatedImages findObjectsInBackgroundWithBlock:^(NSArray *photos, NSError *error) {
PFFile *imageFile = photos[0][@"imageFile"];
NSLog(@"%@", imageFile);
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error){
newGiveItem.giveItemImage = [UIImage imageWithData:data];
}
}];
}];
当我运行这段代码时出现错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'PFObject values may not have class: UIImage'
这似乎没有意义,因为 PFGiveItem 类的给定属性实际上是 UIImage 类型。
最佳答案
你必须使用 PFFile,至少现在是这样。似乎 PFObjectSubclassing,无法将 UIImage 动态处理为 PFFile。一种简单的处理方法是使用 UIImage 公共(public)属性,然后使用 PFFile 私有(private)属性。
#import "PFObject.h"
@interface PFGiveItem : PFObject <PFSubclassing>
@property (retain) UIImage *image;
@end
.m
#import "PFGiveItem.h"
@interface PFGiveItem()
@property (retain) PFFile *imageFile;
@end
@implementation PFGiveItem
@dynamic imageFile;
@synthesize image = _image;
-(UIImage *)image
{
if (!_image){
[self fetchIfNeeded];
_image = [UIImage imageWithData:[self.imageFile getData]];
}
return _image;
}
-(void)setImage:(UIImage *)image
{
_image = image;
self.imageFile = [PFFile fileWithData:UIImagePNGRepresentation(image)];
}
@end
子类项的实现很简单,您只需像使用任何其他局部变量一样使用 UIImage。它有助于 fetchInbackground 然后使用图像来保持解析远离主线程:
PFGiveItem *giveItem = (PFGiveItem *)[PFObject objectWithoutDataWithClassName:@"TableName" objectId:@"objectId"];
[giveItem fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error && object) {
self.backgroundImageView.image = giveItem.image;
}
}];
关于ios - PFObject 值可能没有类 : UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24052510/
[X-Post from parse.com] Person是 PFObject 的子类 . Address也是 PFObject 的子类 . Address有一个 @property类型 Perso
我在 Parse(在 iOS 上)中的当前用户返回正常,它拥有的属性之一是指向 PFObject“A”的指针。因此,当我获得当前用户时,我可以在当前用户中看到指向“A”的有效指针。 我不知道如何从那里
我正在尝试创建一个可以删除以下项目的函数: var array = [23,36,12,45,52,63] removeItem(12,array) result : array = [23,36,4
所以我正在设置这个应用程序,用户可以看到他们的位置,也可以看到其他人的位置。对于脚本,我正在关注这个问题。 how to retrive location from a PFGeopoint - (P
我正在使用 PFObject 子类化,例如: @interface CarObject : PFObject @property (nonatomic, strong) BrandObject *b
我只是想知道最简单/建议的方法是删除 PFObject 及其相关的所有内容。例如,在照片分享应用中,如果上传者想删除他/她发布的照片,您如何同时删除与该照片相关的所有“赞”和评论? 现在,我正在使
假设我有一组“myObject”类的PFObjects(本质上是字典)。此类的对象包含字典键“myDictionary”。反过来,“myDictionary”有一个键“myKey”,我想访问它并搜索与
我在 Xcode 中出现一个错误,提示“Downcast from '[PFObject]?'” '[PFObject]' 只解包可选值;您是要使用“!”吗? var iDArray = [S
Xcode 6.3.1:错误:无法将“PFObject”类型的值分配给“PFObject!”的值 试图理解更严格的 Swift '!'和 '?'要求,因为我认为这是错误的主要原因。 问题出在下面的代码
我正在将解析查询保存到数组中,但在 if letobjects=objectsas? 上出现以下错误? [PF对象] 并且出现以下错误:从“[PFObject]?”向下转型?到“[PFObject]”
我有一个名为 FriendRelation 的 Parse 类。这个类(class)有两个用户,一个是 friend ,另一个是用户。 我想获取用户的所有 friend 发布的所有消息。我尝试使用以下
然后我尝试将键从 PFObject 转换为字符串,但出现错误。我在 Parses 网站上找不到任何内容。请帮忙 var findProgram = PFQuery(className: "Progra
在我的应用程序中,当我尝试注册时,PFObjects 未保存在后台(emailLabel、FirstNameLabel、LastNameLabel、PasswordLabel。知道为什么吗 这是一个代
我已将 userIds 保存在解析为 String 的列中,并且我想将其转换为 PFObject 。我怎样才能快速做到这一点?我试图按如下方式检索 userId: followedUserQuery.
我有一个计时器,可以将当前日期倒计时到我在 Parse 中设置的日期(类名:“Date”)。现在,它使用我设置的 ObjectId 检索该数据。我想将其设置为使用“updatedAt”列中的日期来调用
我已经查看了所有内容,人们说使用 whereKey: equalTo: 可以在数组中工作,但由于某种原因它不适合我。我试图让用户搜索标签,并且包含该标签的所有帖子都会出现。当我删除 whereKey:
我有一个PFObject,Account,其中包含一个User数组,它们是PFUsers的子类。然后,User 有一个 NSDictonary 属性 allowableApps,它是一个 NSDict
我使用 Parse 作为我的后端,我试图让两个子类映射到同一个表。 在我的模型中,我有一个抽象的 Post 类,它符合 PFSubclassing 协议(protocol)并包含几个属性和方法。在我的
我想将来自 Parse 查询的 PFObjects 保存在我的类称为 listdata 的 NSMutableArray 中。我稍后会使用 listdata 数组。当我跟踪我的代码时,它会为找到的每个
我在使用 key 成功检索 PFObject 时遇到问题。对象最后为零: var object = PFObject(className:"Topic") var query = PF
我是一名优秀的程序员,十分优秀!