简体   繁体   English

从Parse.com将徽标图像加载到UIImage中

[英]loading an logo image in to an UIImage from Parse.com

i am trying to load a Logo image in to a UiImage the logo image is in parse but not sure how to load it in to the viewcontroller 我正在尝试将徽标图像加载到UiImage中,徽标图像正在解析中,但不确定如何将其加载到ViewController中

.h file .h文件

@property (weak, nonatomic) IBOutlet UIImageView *Logo;

.m File .m文件

self.Logo.image = [self.exam objectForKey:@"Logo"];

it throws the following error 它引发以下错误

-[PFFile size]: unrecognized selector sent to instance -[PFFile大小]:无法识别的选择器已发送到实例

so i have to use PFfile but not sure how to format it i have searched but most examples have a query invoiled and i dont need the query as the data is there ready in 所以我必须使用PFfile,但不确定如何格式化它,但是我搜索过的大多数示例都调用了查询,并且由于数据已经准备好,所以我不需要查询

self.exam objectForKey:@"Logo"

now added 现在添加

[self.exam objectForKey:@"Logo"];
self.Logo.image = [[UIImage alloc] initWithData: [self.exam objectForKey:@"Logo"]];

but get the following error the image is a .png 但出现以下错误,图像为.png

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFFile length]: unrecognized selector sent to instance

NSlog is showing the file as NSlog将文件显示为

Logo = "<PFFile: 0x111875190>";
[self.exam objectForKey:@"Logo"];

Is instance of class PFFile but not UIImage . 是类PFFile实例,但不是UIImage实例。 You should convert it. 您应该将其转换。 You can try following: 您可以尝试以下操作:

self.Logo.image = [[UIImage alloc] initWithData: [[self.exam objectForKey:@"Logo"] getData]];

PFFile is a subclass of NSObject , thus the UIImage ' length method cannot be called, resulting to your NSInvalidArgumentException. PFFileNSObject的子类,因此无法调用UIImagelength方法,从而导致NSInvalidArgumentException。

You should use an PFImageView instead of your UIImageView. 您应该使用PFImageView而不是UIImageView。

.h file .h文件

@property (weak, nonatomic) IBOutlet PFImageView *Logo;

.m file .m文件

self.Logo.file = [self.exam objectForKey:@"Logo"];
[self.Logo.loadInBackground];

A loadInBackground: method with completion block is also available. 也可以使用带有完成块的loadInBackground:方法。

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

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