4

I don't know if this is possible but I think it could be possible and I dont know how to do this. I simply want to load an image from parse.com like you retrieve objects from parse.com. Should I do it the same way I get strings from parse.com? I just found how to save images on parse but not how to get them. I would be happy if someone could show me a link to do this or a sample code.

I've already set up a string which is retrieved from parse:

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];
                                 }

                             }];

My parse set up:

enter image description here

Thanks.

1 Answer 1

16

Yes, this is possible. If you use web interface to instead of string you should specify PFFile as a type. If you upload image from your iOS client here is a link to parse iOS guide how to do that https://parse.com/docs/ios_guide#files/iOS . Once your image is there you can download image this way:

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];
              }
          }];
     }
 }];
5
  • I'll test it..one moment pls :D Dec 3, 2012 at 20:13
  • Well, all the rest should be the same with the case when you get strings :). You probably need a query to get parseObject (PFObject) which has a PFFile property.
    – dariaa
    Dec 3, 2012 at 20:17
  • The code I gave you implies that PFObject parseObject has a PFFile property named "image"
    – dariaa
    Dec 3, 2012 at 20:21
  • Look at my question below. I updated it. Could you help me with this and implement the retrieving of the image. Dec 3, 2012 at 20:23
  • In germany you say "ich stehe in deiner Schuld" that means something like "I owe you something" ;) Dec 3, 2012 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.