Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 4 AlamofireImage with UITableView Cell

I am using AlamofireImages to try to download an image from a server and display it in my table view cell, this is what I got, but my images does not appear, just the textLabel and detailTextLabel

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "trendingCell", for: indexPath)

        print(self.array[indexPath.row])

        cell.textLabel?.text = (self.array[indexPath.row]["title"] as! String)

        cell.detailTextLabel?.text = (self.array[indexPath.row]["username"] as! String)

        Alamofire.request("http://xxxxxxx.com/uploads/" + (self.array[indexPath.row]["cover"] as! String)).responseImage { response in
            if let image = response.result.value {
                cell.imageView?.image = image
            }
        }

        return cell
    }
like image 835
user979331 Avatar asked May 21 '18 01:05

user979331


1 Answers

Using AlamofireImages

if let url = URL(string: "your url") {

    cell.imageView?.af_setImage(withURL:url, placeholderImage: nil, filter: nil,  imageTransition: .crossDissolve(0.2), runImageTransitionIfCached: false, completion: {response in
      // do stuff when is downloaded completely.
    })
}
like image 133
Umair Afzal Avatar answered Oct 03 '22 17:10

Umair Afzal