title: Calling setCollectionViewLayout:animated does not reload UICollectionView
body: <p>I am using a UICollectionView with two custom layouts - which are subclassed from <code>UICollectionViewFlowLayout</code></p>
  
  <p>When my view first loads I set it to a default view using: </p>
  
  <pre><code>[self.collectionView setCollectionViewLayout:self.tableViewLayout];
  </code></pre>
  
  <p>This calls: <code>cellForItemAtIndexPath</code> - so no problem there. This is in <code>viewWillAppear</code> method.</p>
  
  <p>Then I use a UIButton to change the layout from current view to the next layout like so: </p>
  
  <pre><code>-(void)changeViewLayoutButtonPressed
  {
      self.changeLayout = !self.changeLayout;
  
  
      if (self.changeLayout){
  
          [self.tradeFeedCollectionView setCollectionViewLayout:self.grideLayout animated:YES];
  
      }
  
      else {
  
  
          [self.tradeFeedCollectionView setCollectionViewLayout:self.tableViewLayout animated:YES];
  
      }
  }
  </code></pre>
  
  <p>After this call - <code>numberOfItemsInSection</code> is called. I have checked in the debugger that the return account is not zero. </p>
  
  <p>After that call, nothing else is called and my UICollectionView changes the layout but since <code>cellForItemAtIndexPath</code> is not called - the cells are not setup correctly.</p>
  
  <p>if I put <code>[self.collectionView roloadData]</code> inside of <code>numberOfItemsInSection</code> - then <code>cellForItemAtIndexPath</code> is called and cells are setup. </p>
  
  <p>I shouldn't need to do a manual call to reload the data in <code>numberOfItemsInSection</code>. Can someone tell me whats going on?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I forgot to mention I am using two different UINibs for the two different cells as they need slightly different layouts applied to them. Would this be an issue?
  Thanks!</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Right, so I have gotten it to work almost like I want it to. Here is all the code used for the collection view and how I change its layouts. </p>
  
  <p><strong>The Custom Layouts</strong></p>
  
  <p>These are subclassed from <code>UICollectionViewFlowLayout</code> - The reason I subclassed is simply due to the face my <code>UICollectionView</code> needs to look and behave very close to Apple's pre-made layout. Just different cell sizes, though. </p>
  
  <p><strong>TableViewLayout</strong> 
  - No code in the header file. 
   <strong>- BBTradeFeedTableViewLayout.m</strong></p>
  
  <pre><code>@implementation BBTradeFeedTableViewLayout
  
  -(id)init
  {
      self = [super init];
  
      if (self){
  
          self.itemSize = CGSizeMake(320, 80);
          self.minimumLineSpacing = 0.1f;
      }
  
      return self;
  }
  @end
  </code></pre>
  
  <p><strong>Gride Layout</strong> 
  - No code in the header file. 
   <strong>- BBTradeFeedGridViewLayout.m</strong></p>
  
  <pre><code>   @implementation BBTradeFeedGridViewLayout
  
  -(id)init
  {
      self = [super init];
  
      if (self){
  
          self.itemSize = CGSizeMake(159, 200);
          self.minimumInteritemSpacing = 0.1f;
          self.minimumLineSpacing = 0.1f;
      }
      return self; 
  }
  @end
  </code></pre>
  
  <p>Then in the <code>ViewController</code> that has my <code>UICollectionView</code> - I declare the two custom layouts like so: </p>
  
  <pre><code>@property (strong, nonatomic) BBTradeFeedTableViewLayout *tableViewLayout;
  @property (strong, nonatomic) BBTradeFeedGridViewLayout *grideLayout;
  </code></pre>
  
  <p>I then register the two .xib files for the collectionView:</p>
  
  <pre><code>  [self.tradeFeedCollectionView registerNib:[UINib nibWithNibName:@"BBItemTableViewCell" bundle:nil] forCellWithReuseIdentifier:@"TableItemCell"];
          [self.tradeFeedCollectionView registerNib:[UINib nibWithNibName:@"BBItemGridViewCell" bundle:nil] forCellWithReuseIdentifier:@"GridItemCell"];
  </code></pre>
  
  <p>Then, I have a UIButton that changes the layout: </p>
  
  <pre><code>    -(void)changeViewLayoutButtonPressed
  {
  
      if (!self.gridLayoutActive){
  
          self.gridLayoutActive = YES;
          [self.tradeFeedCollectionView setCollectionViewLayout:self.grideLayout animated:YES];
          self.lastLayoutUsed = @"GridLayout";
  
      }
  
      else {
  
          self.gridLayoutActive = NO;
  
          [self.tradeFeedCollectionView setCollectionViewLayout:self.tableViewLayout animated:YES];
          self.lastLayoutUsed = @"TableLayOut";
      }
      [self.tradeFeedCollectionView reloadItemsAtIndexPaths:[self.tradeFeedCollectionView indexPathsForVisibleItems]];
  
  }
  </code></pre>
  
  <p>Finally - when a web service call is done - it calls <code>[self.tradeFeedCollectionView reloadData];</code></p>
  
  <p>So there my <code>UICollectionView</code> gets reloaded and the last method: </p>
  
  <pre><code> -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  
  {   static NSString *tableCellIdentifier = @"TableItemCell";
      static NSString *gridCellIdentifier = @"GridItemCell";
  
      if (indexPath.item &lt; [self.tradeSearchArray count]){
  
      if (self.gridLayoutActive == NO){
  
          BBItemTableViewCell *tableItemCell = [collectionView dequeueReusableCellWithReuseIdentifier:tableCellIdentifier forIndexPath:indexPath];
  
      if ([self.tradeSearchArray count] &gt; 0){
  
          self.toolBarButtomItem.title = [NSString stringWithFormat:@"%d Results", self.searchResult.searchResults];
  
          tableItemCell.gridView = NO;
          tableItemCell.backgroundColor = [UIColor whiteColor];
          tableItemCell.item = self.tradeSearchArray[indexPath.row];
  
      }
          return tableItemCell;
  }else
  
      {
  
          BBItemTableViewCell *gridItemCell= [collectionView dequeueReusableCellWithReuseIdentifier:gridCellIdentifier forIndexPath:indexPath];
  
      if ([self.tradeSearchArray count] &gt; 0){
  
          self.toolBarButtomItem.title = [NSString stringWithFormat:@"%d Results", self.searchResult.searchResults];
  
  
          gridItemCell.gridView = YES;
          gridItemCell.backgroundColor = [UIColor whiteColor];
          gridItemCell.item = self.tradeSearchArray[indexPath.row];
  
      }
  
      return gridItemCell;
      }
  </code></pre>
  
  <p><strong>The problem with the above code</strong></p>
  
  <p>The above code does work. However, the cells don't animate nicely and it looks odd, almost as if a refreshed happened. Which is due to calling:</p>
  
  <p><code>[self.tradeFeedCollectionView reloadItemsAtIndexPaths:[self.tradeFeedCollectionView indexPathsForVisibleItems]];</code></p>
  
  <p>But that is the only way I could get it to be close to what I want. </p>