如何将图像从Parse加载到UIImageView(iOS)
我可能会问一些非常简单的事情,但我找不到能够帮助我的教程或示例。
我已经学会了如何从Parse检索字符串数据,现在我正在尝试检索图像,认为它会更容易……但我无法弄明白。
我正在尝试在UIImageView
加载1张图像(我将每天更换),从Parse.com中的数据浏览器中检索图像。
有人可以帮忙吗?
这就是我所做的:
- (void)viewDidLoad { [super viewDidLoad]; [self performSelector:@selector(retrieveFromParse)]; } - (void) retrieveFromParse { PFQuery *retrieveImage = [PFQuery queryWithClassName:@"outfitDay"]; [retrieveImage findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { loadimageArray = [[NSArray alloc] initWithArray:objects]; } }]; }
我错过了指示UIImageView
加载该信息的部分。
提前致谢!!
您可以借助此代码在UIImageView中设置图像。如果您想在url的帮助下在imageview中设置图像,您可以尝试此代码。为此,您必须下载SDWebImages库
PFObject *objFollow1 = ["your array of PFObject" objectAtIndex:your index]; PFFile *image = [objFollow1 objectForKey:@"your key"]; NSLog(@"%@",teaserImage.url); [your imageview setImageWithURL:[NSURL URLWithString:[teaserImage url]]];
如果你不想下载图像格式url,那么你必须将此PFFile转换为NSData然后转换为UIImage
您可以通过以下代码使用解析设置图像…如果您将图像存储为PFFile ….
PFFile *eventImage = [[loadimagesarray objectAtIndex:indexPath.row] objectForKey:@"ProfileImageFile"]; //ProfileImageFile is the name of key you stored the image file if(eventImage != NULL) { [eventImage getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) { UIImage *thumbnailImage = [UIImage imageWithData:imageData]; UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage]; cell.yourimageview.image = thumbnailImageView.image; }]; }
如果您想要如何检索详细信息并将其保存在loadimagesarray中,请使用以下代码。
- (void)retrieveDetails { PFQuery *query = [PFQuery queryWithClassName:@"outfitDay"]; __block int totalNumberOfEntries = 0; [query orderByDescending:@"createdAt"]; [query countObjectsInBackgroundWithBlock:^(int number1, NSError *error) { if (!error) { // The count request succeeded. Log the count totalNumberOfEntries = number1; if (totalNumberOfEntries > [loadimagesarray count]) { NSLog(@"Retrieving data"); //query.skip=[NSNumber numberWithInt:2300]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { // The find succeeded. NSLog(@"Successfully retrieved %d chats.", objects.count); int j=[loadimagesarray count]; if([objects count]>j) { [loadimagesarray addObjectsFromArray:objects]; } } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); } }]; } } else { // The request failed, we'll keep the chatData count? number1 = [loadimagesarray count]; } }]; }
希望对你有帮助..
使用PFImageView类可以轻松地从解析中加载图像。 下面是从Parse加载PFFile并在PFImageView中显示它的示例(如果找不到远程文件,则使用本地占位符图像):
PFImageView *profileImageView; // User thumbnail PFFile *imageFile = [self.author objectForKey:FIELDNAME_PROFILE_PROFILEPICTUREFILE]; if (imageFile) { profileImageView.file = imageFile; [profileImageView loadInBackground]; } else { profileImageView.image = [UIImage imageNamed:@"AvatarPlaceholder.png"]; }
在您的情况下,您可能会从刚刚检索到的数组中获取图像…
对于任何需要帮助的人! 我找到了问题的答案。
在此示例中找到它: https : //parse.com/questions/retrieve-images-from-parse-to-uiimageview
希望它对其他人有帮助!!
感谢所有花时间回答我的问题!
- 如何在ios中准备好几个月和几年的UIPickerView?
- 在iphone中可扩展的tableView
- 'UITableView'没有@interface声明select器'initWithStyle:reuseIdentifiers
- 实现核心数据watchOS 2.0
- Bridging-header.h导致命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc失败,退出代码1
- UITapGestureRecognizer在多次点击时崩溃
- 错误无法使类型UICollectionElementKindCell的视图出列
- 如何在Xcode中构build一个iOS框架的发布版本?
- 在NSOperation中使用委托