Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Rashii Henry
16,433 PointsDownloading a PFFile(image) into the backgroundImage of a cell?
I've already saved the photo to Parse using
NSString *filename = [NSString stringWithFormat:@"%@.png", _nameText.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
//[shoePic setObject:imageFile forKey:@"Image"];
PFObject *jordanObject = [PFObject objectWithClassName:@"Jordans"];
jordanObject[@"jordanName"] = filename;
jordanObject[@"jordanImage"] = imageFile;
[jordanObject saveInBackground];
of course Im using the saveInBackgroundWithBlock but for brevity in the context of this question it creates a table with a column for the imageFile, with the column title referencing the string literal above.
How can i retrieve this file and set it as the backgroundImage of my collectionview cell.
i've used this in cellForItemAtIndexPath:
PFQuery *query = [PFQuery queryWithClassName:@"Jordans"];
//[query orderByAscending:@"jordanName"];
[query getObjectInBackgroundWithId:[self.shoe.jordanShoeNames objectAtIndex:0] block:^(PFObject *jordanObject, NSError *error) {
// Do something with the returned PFObject in the JordanObject variable.
jordanObject = [PFObject objectWithClassName:@"Jordans"];
PFFile *imageFile = jordanObject[@"jordanImage"];
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:imageData];
NSLog(@"the data: %@", imageData);
cell.jordanShoePhoto.image = image;
}
}];
but i keep getting a nil JordanObject, by the way, the array passed into the block holds the objectID geneated by parse for the image.
Rashii Henry
16,433 PointsRashii Henry
16,433 PointsBen Jakuben, Pasan Premaratne, Amit Bijlani any suggestions?