繁体   English   中英

如何将图像从Parse加载到UIImageView(iOS)

[英]How to load an image from Parse into a 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]]];

如果您不想下载图像格式网址,则必须将此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

希望对别人有帮助!

感谢所有花时间回答我的问题!

暂无
暂无

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

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