I have a swift project with the following files:
– ViewController.swift
which mostly contains a tableView and in which data from Firebase is downloaded
– ViewControllerTableViewCell.swift
which contains the outlets for the tableView
– DataModel.swift
which contains the model for the Firebase data
In the table, I have included some labels which are filled with the data from Firebase, next to an imageView. The URL of the image is received in the ViewController.swift
-file as authorAvatarUrl
next to other strings from Firebase. After this process, the data is appended to a list (self.dataList.append(downloadeddata)
) and the table is reloaded:
self.tableViewData.reloadData()
How can I download the image and display it in the imageView (which is inside a table cell)?
I have tried
// Declare variable
var cellViewController = ViewControllerTableViewCell()
[...]
// Download author's avatar
let avatarURL = URL(string: authorAvatarUrl as! String)
Alamofire.request(avatarURL!).responseData { (response) in
if response.error == nil {
if let data = response.data {
self.cellViewController.profileImageView.image = UIImage(data: data)
}
}
}
inside the ViewController.swift
-file however, this is not working.