title: iPhone: Scroll to last item in UICollectionView
body: <p>Im creating a viewcontroller with an <strong>UICollectionVIew</strong> with the images from the users library. </p>
  
  <p>After the assets are loaded and i reload the data from the UICollectionView, i try to scroll to the last item in the UICollectionView. </p>
  
  <p>The UICollectionView is filled, but i receive an error when scrolling to the last object.</p>
  
  <p>Here's my code </p>
  
  <pre><code>void (^assetEnumerate)(ALAsset *result, NSUInteger index, BOOL *stop) = ^(ALAsset* result, NSUInteger index, BOOL *stop){
      if (result != nil){
          [_assets addObject:result];
      }
  };
  
  void (^ALAssetsLibraryGroupsEnumerationResultsBlock)(ALAssetsGroup *group, BOOL *stop) = ^(ALAssetsGroup *group, BOOL *stop){
      if(group != nil){
          [group enumerateAssetsUsingBlock:assetEnumerate];
          [_collectionView reloadData];
  
          //OLD:
          //no mather what is filled in the indexPathForRow, it results in an error
          //[_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
  
          //NEW: fix!
          dispatch_async(dispatch_get_main_queue(), ^{
              [_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:[_collectionView numberOfItemsInSection:0] inSection:0] atScrollPosition:UICollectionViewScrollPositionBottom animated:NO];
          });
      }
  };
  
  void (^ALAssetsLibraryAccessFailureBlock)(NSError *error) = ^(NSError *error){
      NSLog(@"ERROR: Couldn't enumerate group");
  };
  
  [_library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:ALAssetsLibraryGroupsEnumerationResultsBlock failureBlock:ALAssetsLibraryAccessFailureBlock];
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>*** Assertion failure in -[UICollectionViewData layoutAttributesForItemAtIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UICollectionViewData.m:485
  2012-11-06 00:53:17.388 iBoob[6016:c07] *** 
  Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'must return a UICollectionViewLayoutAttributes instance from -layoutAttributesForItemAtIndexPath: for path &lt;NSIndexPath 0x968af20&gt; 2 indexes [0, 0]'
  *** First throw call stack:
  (0x2988012 0x14e7e7e 0x2987e78 0xf7df35 0x95f3f2 0x93794e 0xa7e4 0x3fd46 0x2981e7c 0x2981a16 0x2981925 0x3fb8c 0x33eb53f 0x33fd014 0x33ed7d5 0x292eaf5 0x292df44 0x292de1b 0x20ca7e3 0x20ca668 0x42f65c 0x60cd 0x2ab5)
  libc++abi.dylib: terminate called throwing an exception
  </code></pre>