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

iOS Implementing Designs for iPhone Finishing the User Interface Getting Images Using Grand Central Dispatch

can we save the user profile picture in parse and then load it in the background

who knows a better idea , because i think using only one database will save for us more time

2 Answers

Meek, Parse makes this kind of functionality easy. I spent some time doing this in Lion, my app.

I used this code to get the image in tableView:cellForRowAtIndexPath:

//Assuming that you have an array of friends in your project, this will get that user that was tapped on.
PFUser *user = self.friends[indexPath.row];

//Get the profile image file from the user tapped on with the shorthand objectForKey: syntax.
PFFile *profileImageFile = user[@"ProfileImage"];

[profileImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
    if (!error && imageData)
    {
        //If there was no error with the internet request and some kind of data was returned, use that data to form the profile image with the handy method of UIImage.

        //Set the image view to the image with the data returned from Parse.
        cell.imageView.image = [UIImage imageWithData:imageData];
    }
    else
    {
        //Use Ben Jakuben's easy to read error printing technique.
        NSLog(@"Error: %@ %@", error, [error localizedDescription]);
    }
}];

It's usually a bad idea to save any binary data such as images and PDFs on an actual database, but Parse designed their API to in fact handle cases you want to upload images for use with Parse Core within your app.

If you want a hand-on tutorial demonstrating how you do it, Parse has provided a tutorial on how to do it.

i am not talking about general pictures , i want to know is there any way to save the profile picture and the username the parse database and load it through any view controller i want