title: UICollectionView inside an UITableViewCell
body: <p>I've noticed iOS it's very mean when using <code>UICollectionView</code> inside an <code>UITableViewCell</code>. What I'm trying to achieve, it's to have a Collection of Images (<code>UICollectionView</code> approach) inside a <code>UITableViewCell</code>. I'm trying to mimic Facebook post style, I think, they have an <code>UITableView</code>, with custom cells and so on, but <strong>here's</strong> the Problem...</p>
  
  <p>I've managed to put the <code>UICollectionView</code> inside an <code>UITableViewCell</code>, and It worked correctly and perfectly, no problem, everything showing fine, it's clickable and so on. BUT, I tried to refactor my code, extracting the <em><code>UICollectionViewDataSource</code></em> &amp; <em><code>UICollectionViewDelegate</code></em> into separate files for Reusing them and having less code on the <code>Main View Controller</code>, it is here, when my <strong>Nightmare</strong> begun, I don't know why if I'm using separate files iOS Cycles the configuration of the Cells. For example:</p>
  
  <pre><code>-(void)configureCell:(UICollectionViewCell*)customCell atIndexPath:(NSIndexPath*)indexPath;
  </code></pre>
  
  <p>The above method it's being called on two parts of the process:</p>
  
  <pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   NSString *identifier = [self retrieveIdentifierForIndexPath:indexPath];
   UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:identifier];
   [self configureCell:myCell atIndexPath:indexPath];
   [cell setNeedsLayout];
   [cell layoutIfNeeded];
   [cell setNeedsUpdateConstraints];
   [cell updateConstraintsIfNeeded];
   CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingExpandedSize].height;
   return height;
  }
  </code></pre>
  
  <p>The above method it's invoked to calculate the Row Height using AutoLayout I read this on a Post here at <strong>StackOverFlow</strong> ( don't remember the post :( )</p>
  
  <p>After the height it's being calculated and so on, another method calls the "<code>configureCell</code>" method:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      NSString *rowName = [self retrieveIdentifierForIndexPath:indexPath];
      PostDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rowName forIndexPath:indexPath];
  
      //PreCondition
      if([rowName isEqualToString:@"LoadingRow"]){
          return cell;
      }
  
      // Configure the cell...
      [self configureCell:cell atIndexPath:indexPath withImages:YES];
  
      [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  
      return cell;
  }
  </code></pre>
  
  <p>When the debugger starts, the method <em><code>configureCell:atIndexPath:</code></em> it's being called over and over and over again. this is the second time this happens. Does that mean that I can't "separate" the <code>DataSource</code>? Or <strong><em>IT IS IMPOSSIBLE</em></strong> to add an <code>UICollectionView</code> inside an <code>UITableViewCell</code>. Or, Am I using a bad approach? Is there a way to do this? </p>
  
  <p>I'm very confused on this...</p>
  
  <p>Thank you guys!</p>