Search code examples
iosswiftsegue

can't pass image from tableViewCell to detailVC through segue


I try to pass my image from the tableViewCell to the detailVC if the cell get tapped, but the imageView on the detailVC is empty where normally the image from the cell should be... My current code works for textLabels as an example, but somehow not for the image


Solution

  • Opinionated Solution

    The code here suggests that you are using Firebase. Retrieving images from Firebase requires:

    1. A reference to the download URL of the image ( as you have)
    2. An extra call to actually download the image from your storage container (not sure if you are doing this in other parts of your code not shared)

    Regardless, you should not send the actual image to the detailVC in my opinion. Try instead to send the download URL and attempt to download the image in detailVC, or to pull it from cache if you are caching. The reason for this is, imagine if the user clicks on a cell when the image has not finished downloading (he/she may know from other cell details that this is the cell of interest), would you wait for the image to download before displaying the detailVC? That seems contrary to what a user would expect. So it may just be better to handle the downloadURL instead of the whole image.

    Just throwing this out there in case: Make sure that when you finish downloading your image you call the main thread to update the UIImage. Read about it here for reference.