4

我不知道这是否可能,但我认为这是可能的,我不知道该怎么做。我只是想从 parse.com 加载图像,就像从 parse.com 检索对象一样。我应该像从 parse.com 获取字符串一样吗?我刚刚找到了如何在解析时保存图像,但没有找到如何获取它们。如果有人可以向我展示执行此操作的链接或示例代码,我会很高兴。

我已经设置了一个从解析中检索到的字符串:

PFQuery *query = [PFQuery queryWithClassName:@"app"];
[query getObjectInBackgroundWithId:@"ID"
                             block:^(PFObject *textdu, NSError *error) {
                                 if (!error) {



                                     UIFont *welcomeLabelFont = [UIFont boldSystemFontOfSize:17];

                                     welcomeLabel.text = [textdu objectForKey:@"ueberschriftnews"];
                                     welcomeLabel.font = welcomeLabelFont;
                                     welcomeLabel.textColor = [UIColor whiteColor];
                                     welcomeLabel.textAlignment = NSTextAlignmentCenter;
                                     welcomeLabel.backgroundColor = [UIColor clearColor];
                                     welcomeLabel.shadowColor = [UIColor blackColor];
                                     welcomeLabel.shadowOffset = CGSizeMake(0, 1);
                                     [contentView addSubview:welcomeLabel];



                                     // The get request succeeded. Log the score
                                     NSString *text = [textdu objectForKey:@"newstext"];
                                     UIFont *font = nil;
                                     CGFloat points = 17;
                                     CGFloat maxHeight = infoLabel.frame.size.height;
                                     CGFloat textHeight;
                                     do {
                                         font = [UIFont systemFontOfSize:points];
                                         CGSize size = CGSizeMake(infoLabelRect.size.width, 100000);
                                         CGSize textSize = [text sizeWithFont:font constrainedToSize:size lineBreakMode: NSLineBreakByWordWrapping];
                                         textHeight = textSize.height;
                                         points -= 1;
                                     } while (textHeight > maxHeight);
                                     infoLabel.text = text;
                                     infoLabel.numberOfLines = 9;
                                     infoLabel.font = font;
                                     infoLabel.textColor = [UIColor whiteColor];
                                     infoLabel.textAlignment = NSTextAlignmentCenter;
                                     infoLabel.backgroundColor = [UIColor clearColor];
                                     infoLabel.shadowColor = [UIColor blackColor];
                                     infoLabel.shadowOffset = CGSizeMake(0, 1);

                                     [infoLabel sizeToFit];
                                     [contentView addSubview:infoLabel];

                                 } else {

                                     infoLabel.text = @"something";
                                     [infoLabel sizeToFit];
                                     [contentView addSubview:infoLabel];
                                 }

                             }];

我的解析设置:

在此处输入图像描述

谢谢。

4

1 回答 1

16

是的,这是可能的。如果您使用 Web 界面而不是字符串,则应将 PFFile 指定为类型。如果您从 iOS 客户端上传图像,这里有一个解析 iOS 指南的链接https://parse.com/docs/ios_guide#files/iOS。一旦你的图像在那里,你可以通过这种方式下载图像:

PFQuery *query = [PFQuery queryWithClassName:@"app"];
[query getObjectInBackgroundWithId:@"ID"
                         block:^(PFObject *textdu, NSError *error) {
{
     // do your thing with text 
     if (!error) {
          PFFile *imageFile = [textdu objectForKey:@"image"];
          [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
              if (!error) {
                  UIImage *image = [UIImage imageWithData:data];
              }
          }];
     }
 }];
于 2012-12-03T20:01:29.000 回答