{"id":4293,"date":"2014-03-30T09:44:02","date_gmt":"2014-03-30T09:44:02","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/uicollectionview-scrolling-choppy-when-loading-cells-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:44:02","modified_gmt":"2014-03-30T09:44:02","slug":"uicollectionview-scrolling-choppy-when-loading-cells-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/uicollectionview-scrolling-choppy-when-loading-cells-collection-of-common-programming-errors\/","title":{"rendered":"UICollectionview Scrolling choppy when loading cells-Collection of common programming errors"},"content":{"rendered":"<p>I have a gallery in my app utilizing a UICollectionView. The cells are approximately 70,70 size. I am using ALAssets from the ALAssetLibrary in the gallery which I have stored in a list.<\/p>\n<p>I am using the usual pattern for populating the cells:<\/p>\n<pre><code>-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath\n{\n\n  mycell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];\n  mycell.imageView.image = [[UIImage imageWithCGImage:[alassetList objectAtIndex:indexpath.row] thumbnail]];\n  return mycell;\n}\n<\/code><\/pre>\n<p>My gallery is scrolling choppy. I don&#8217;t understand why this is. I&#8217;ve tried adding a NSCache to cache the thumbnail images (thinking maybe creating the images was expensive) but this did not help for the performance.<\/p>\n<p>I would expect the UI to be as buttery as the stock app.<\/p>\n<p>I am now suspecting it may be something in the <code>UICollectionViewCell prepareForReuse<\/code> that may be holding up the <code>dequeueReusableCellWithReuseIdentifier<\/code> method but using instruments I was not able to find this.<\/p>\n<p>Any other thing that may be be causing this? Is there a &#8220;faster&#8221; way to prepare the UICollectionViewCell or to dequeue them in a faster fashion?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a gallery in my app utilizing a UICollectionView. The cells are approximately 70,70 size. I am using ALAssets from the ALAssetLibrary in the gallery which I have stored in a list. I am using the usual pattern for populating the cells: -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { mycell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; mycell.imageView.image = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4293","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4293"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4293\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}