1

Description/ What I've tried

I imported a library that lets me beautifully load images asynchronously into my UITableView (https://github.com/natelyman/SwiftImageLoader) . The problem is that it doesn't support gifs. So I did case statement to independently retrieve the gif if need be and display the gif using another library.

Problem

Now the problem is that whenever I try loading a gif, the scrolling gets really choppy.

Question

Can someone please help me figure this out? Does it involve putting it on a background thread? If so, how?

Code

if let url = NSURL(string: arrayByVotes[indexPath.row].objectForKey("thumbnail") as NSString) {

        let imageURL = arrayByVotes[indexPath.row].objectForKey("thumbnail") as NSString

        if (imageURL.lowercaseString.rangeOfString("gif") != nil) {

                    cell.thumbnail.image = UIImage.animatedImageWithAnimatedGIFURL(url)


        } else {

            ImageLoader.sharedLoader.imageForUrl(arrayByVotes[indexPath.row].objectForKey("thumbnail") as NSString, completionHandler:{(image: UIImage?, url: String) in

                cell.thumbnail.image = image
            })

        }

    }
Chris Jones
  • 856
  • 1
  • 11
  • 24

1 Answers1

-1

Maybe having many gif images in memory at the same time is affecting the performance of the scrolling. Try removing the images from the cells that are invisible and add the image only when the cell will show up. A good method for this would be tableView(_:willDisplayCell:forRowAtIndexPath:) from the UITableViewDelegate

OscarVGG
  • 2,632
  • 2
  • 27
  • 34