简体   繁体   中英

Add Images to TableView cells from Firebase in Swift

I am making a social App with Firebase - I want to take each picture the user has uploaded (each user upload only 1 picture) and add it to an array, and then to show it in each cell (each cell is different user with his uniqe uploaded image).

So far I haven't even have any code because i have no idea where to start.. /:

Firebase provides no simple way to upload profile pictures for users. I would suggest using a 3rd party site, such as Cloudinary . Then, you will store a link to an image in your user's profile information, using a unique identifier (I would recommend by user ID). Now, you have a whole bunch of user objects with their own profile picture URL's.

Next step, we need to load these URL's to become images in table view cells. To do this, there's a great library called SDWebImage that allows you to asynchronously load images from URL's. This means, they will load in without interupting anything else you are trying to do on that controller, and will show a placeholder image until fully loaded. Once you add this library, you have 2 steps:

First step: Import

#import "UIImageView+WebCache.h"

Next step: Load the image w/ placeholder in cellForRowAtIndexPath (Use a custom cell that has a UIImageView inside it).

//user.picUrl is this specific user's profile picture URL
//placeholder.png is a png file in your project's resources
[cell.imageView sd_setImageWithURL:user.picUrl placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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