TableViewCell ImageView shows always different data

uitableviewcell load image from url swift 4
uitableview cells overlapping swift
add image to uitableviewcell swift
uitableview with multiple custom cells tutorial
uitableviewcell image change when scroll
custom uitableviewcell swift programmatically
custom uitableviewcell objective-c
uitableviewcell example

I have a chat and want to display the users profile pictures. Everything will be displayed correctly but not the profile pictures of the users. Everytime, when I reload my view, I get other pictures.

I load the Profileimage in with the following lines:

func showProfilImage(uid: String, completion: @escaping (UIImage) -> Void) {
    UserApi.shared.observeUser(uid: uid) { (user) in
        guard let url = URL(string: user.profilImageUrl!) else { return }

        URLSession.shared.dataTask(with: url) { (data, response, error) in
            guard error == nil, let data = data, let image = UIImage(data: data) else { return }
                DispatchQueue.main.async {
                    let finishedImage = image.withRenderingMode(.alwaysOriginal)

Then I call showProfilImage in cellForRowAt with the following lines:

self.showProfilImage(uid: self.items[indexPath.row].user.uid!) { (image) in
    cell.profilePic.image = image


Now i implemented sdWebImage and make a completion with the URL:

func showProfilImage(uid: String, completion: @escaping (URL) -> Void) {
    UserApi.shared.observeUser(uid: uid) { (user) in
        guard let url = URL(string: user.profilImageUrl!) else { return }

Here I call my showProfilImage:

self.showProfilImage(uid: self.items[indexPath.row].user.uid!) { (url) in
            cell.profilePic.image = nil
            cell.profilePic.sd_setImage(with: url, completed: { (_, _, _, _) in

Your current code has dequeuing and no cashing problems and the right for that is to use SDWebImage

cell.profilePic.sd_setImage(with: URL(string:urlStr), placeholderImage: UIImage(named: "placeholder.png"))

also something like

UserApi.shared.observeUser(uid: uid) { (user) in

would be once say in viewDidLoad

Take Control of Numbers, Graphics Are Not Data It seems that you can put an image in a cell: with an can even paste in a video or audio file and its associated image shows in the cell. includes the other (although it's not always displayed in the cell): Date: Enter  The data source can use two different ways to access the subviews of the cells. One approach uses the tag property defined by UIView and the other approach uses outlets. Using tags is convenient, although it makes the code more fragile because it introduces a coupling between the tag numbers in the storyboard and the code.

If you're fetching the image correctly for each user then you problem might be laying in scrolling and dequeuing the cell to solve such issue inside the UITableViewCell custom class use this function to clear out the UIImageView each time a dequeue happens.

override func prepareForReuse() {
        self.imageView.image = nil  //setting the image to nil  when get dequeued to reuse 

Read more about this function Here

The Focal Encyclopedia of Photography, Digital data representing an image must always be converted by some technical a digital image will again result in a digital image, which differs from the original image. Figure 39 shows a gray value image where in each memory cell the  Display different images for different rows – lastly, we display the same thumbnail for all rows. Wouldn’t be better to show individual image for each recipe? Customize the table view cell – instead of using the default style of table view cell, we’ll take a look how to build our own.

UITableView reuses its views that means when you load an image one time and cell goes out of screen UITableView will bring the cell back to screen for different data source but the image that previously loaded will still presented on the UIImageView add this line of code

cell.profilePic.image = nil
self.showProfilImage(uid: self.items[indexPath.row].user.uid!) { (image) in
        cell.profilePic.image = image

The Biology and Therapeutic Application of Mesenchymal Cells, 2 , Four FOVs are stitched together to form one larger FOV for cell tracking. (A) Fluorescent image shows raw images after stitching and (B) the final result applied for wide-field imaging using multiple contiguous FOVs is image stitching. backup terabytes of data although such services do not always have network speeds  Each enum case represents the data type that requires the different TableViewCell. But because we want to use our data within the same tableView, so need to have the single DataModelItem , that

Load local images asynchronously in the table view, Table views have always been the most popular guests for many apps. In fact, more The image loading time is longer than other content. If the image override func numberOfSections(in tableView: UITableView) -> Int { return 1 } lazyImageView.image = UIImage(data:images[indexPath.row].imageData  Open TableViewCell.xib and add elements like the below: The cell consists of a photoView to display the image, quoteTextLabel to display the quote, and a nameLabel to display the name. ImageView

Creating a reusable UITableViewCell * Equaleyes Blog, Imagine a UITableViewCell implementation of a cell that is being used When we code, we always try not to repeat ourselves. some of the components and populate this cell with different data on every screen. We would hide the image view when displaying the user data and show the image view  In this tutorial, we are going to see how to create a circular image view and a circular image view with border-color in Android. Most of the time the android developers use a third-party library for creating a circular profile image, but this tutorial will explain how to create a circular image view without the help of the third-party library and plugins as well.

Configuring the Cells for Your Table, For most tables, you provide only one or two different types of cells. At runtime, the table's data source object creates actual cells from the prototypes and configures them with your app's data. Illustration showing a table with four prototype cells. Most of the styles also incorporate an image at the leading edge of the cell's  A Xamarin.Forms ViewCell is a cell that can be added to a ListView or TableView, which contains a developer-defined view. This article demonstrates how to create a custom renderer for a ViewCell that's hosted inside a Xamarin.Forms ListView control.

  • Don't load the (same) pictures a zillion times in cellForRow, load it once per user when populating the data source in the controller or in the model. At least use something to cache the images.
  • updated my question. I now implemented sdWebImage but still the same problem. Thanks in advance for your help!
  • i guess observeUser is called many times and the user profile is changed also ?
  • I call observeUser only once in the code. It will be called for every tableViewCell (this time I have 4 users/conversations). So it will be called 4 times. Right?
  • it will be called 4 times , and when you scroll the one that hides and reshown will be called again , consider doing all of this once by starting a background calls to all the images when the vc is shown may be in viewDidLoad then refresh the table
  • no need of the showProfilImage anymore. Just call that line of code: let imageUrl = URL(string: self.items[indexPath.row].user.profilImageUrl!) cell.profilePic.sd_setImage(with: imageUrl) { (_, _, _, _) in } in items, I have all the users, so I don't need to load them a second time. No problems with this code!