我无法从PFFile获取图像 [英] I can't get image from PFFile
本文介绍了我无法从PFFile获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Parse.com刚刚更新了其SDK,以支持本地存储.但是在安装新的SDK之后,PFFile出现了一些问题.我已经使用相同的方法很长时间了,但是现在我正在使用新的SDK,因此无法正常工作.
Parse.com just updated their SDKs to support local storage. But after installing new SDKs I have occurred some problems with PFFile. I have used the same method for a long time, but now that I'm using the new SDK I can't get it to work.
这是我的代码:
.h文件
@property (strong, nonatomic) IBOutlet PFFile *iconPhoto;
.m文件
cell.iconPhoto.image = [UIImage imageNamed:@"placeholder.png"]; // placeholder image
cell.iconPhoto.file = (PFFile *)object[@"icon"]; // remote image
[cell.iconPhoto loadInBackground:^(UIImage *image, NSError *error) {
cell.iconPhoto.image = image;
cell.userInteractionEnabled = YES;
}];
我跑步时得到这些错误(链接)
其他人也有同样的问题吗?
Is someone else having the same problems?
更新:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
});
static NSString *CellIdentifier = @"Cell";
MainTVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFObject *object = [self.currentCategories objectAtIndex:indexPath.row];
cell.mainLabel.text = object[@"name"];
cell.userInteractionEnabled = YES;
if (![object[@"icon"] isEqual:[NSNull null]]) {
cell.image = [UIImage imageNamed:@"loading.png"]; // placeholder image
cell.iconPhoto = (PFFile *)object[@"icon"]; // remote image
[cell.iconPhoto getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error && imageData) {
cell.image = [UIImage imageWithData:imageData];
cell.userInteractionEnabled = YES;
}
}];
}
return cell;
}
推荐答案
我自己找到了解决方案.
I found a solution myself.
PFFile *file = (PFFile *)object[@"icon"];
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
cell.iconImageView.image = [UIImage imageNamed:@"placeholder.png"]; // placeholder image
cell.iconImageView.image = [UIImage imageWithData:data];
cell.userInteractionEnabled = YES;
}];
这将加载图像. 奇怪的是它不会在模拟器中运行.但是可以在iPhone上完美运行.
This will load the images. Weird thing it won't run in the simulator.. But works perfectly on iPhone.
这篇关于我无法从PFFile获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文