1

I'm trying to display Gifs in a collection view with URL downloaded from Firebase. I already tried using Gifu import. Any idea on how to load the Gif into the collection view?

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return self.posts.count
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
       return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier:"gifCell", for: indexPath) as! GifPostCell

    //cell.gifPostImage.downloadImage(from: self.posts[indexPath.row].pathToGif)
    cell.gifPostImage.animate(withGIFURL: self.posts[indexPath.row].pathToGif)

    return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print("User photo selected: \(indexPath.row)")
}
  • Welcome to Stackoverflow. Please post your code in code format, and not as a screenshot. – Glenn Posadas Mar 03 '20 at 17:13
  • Thanks! Already edit it. – demonisback Mar 03 '20 at 17:17
  • There's a lot of code missing from your question - from initializing the animator to validating the path to the gif is valid. Take another look a the [GIFU](http://kaishin.github.io/Gifu/index.html) website and ensure the animator is initialized correctly, all of the needed code is in place, and the path is valid. Also, examine your function call as you're returning a `UICollectionViewCell`, not a `GifPostCell` - which may or may not be an issue. – Jay Mar 03 '20 at 18:49
  • Check this out, it may be useful https://stackoverflow.com/questions/27919620/how-to-load-gif-image-in-swift – Ahmed Abd Elaziz Mar 03 '20 at 21:08

0 Answers0