title: UICollectionView sizeForItemAtIndexPath
body: <p>I'm having a problem with my UICollectionViewCell when setting it's height programatically. When the collection first load it appears ok, but when the collection is scrolled the cell lose it's height.</p>
  
  <p>This is how it looks before the scrolling: <a href="https://dl.dropboxusercontent.com/u/11335239/Captura%20de%20Tela%202013-09-05%20%C3%A0s%2016.18.41.png" rel="nofollow noreferrer">https://dl.dropboxusercontent.com/u/11335239/Captura%20de%20Tela%202013-09-05%20%C3%A0s%2016.18.41.png</a></p>
  
  <p>This is after the scrolling: <a href="https://dl.dropboxusercontent.com/u/11335239/Captura%20de%20Tela%202013-09-05%20%C3%A0s%2016.18.46.png" rel="nofollow noreferrer">https://dl.dropboxusercontent.com/u/11335239/Captura%20de%20Tela%202013-09-05%20%C3%A0s%2016.18.46.png</a></p>
  
  <p>To calculate se cell height i'm using the method:</p>
  
  <pre><code>- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      NSString *texto = ([[self.jsonMensagem objectAtIndex:indexPath.row] objectForKey:@"conteudo"] != [NSNull null]) ? [Metodos formatarTexto:[[[self.jsonMensagem objectAtIndex:indexPath.row] objectForKey:@"conteudo"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]] : @"";
  
      float height = [texto sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0] constrainedToSize:CGSizeMake(220.0, 99999.0f) lineBreakMode:NSLineBreakByWordWrapping].height;
  
      NSLog(@"\n\nText: %@\nheight: %f", texto, height);
  
      tamanho = CGSizeMake(310.0, (height &gt; 50) ? height + 20 : 60);
  
      return tamanho;
  }
  </code></pre>
  
  <p>This is what it returns:</p>
  
  <blockquote>
    <p>Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. In
    consequat nunc a erat faucibus, sit amet interdum ipsum auctor.
    Praesent sagittis feugiat aliquet. Phasellus dictum laoreet auctor.
    Nulla aliquet enim ut ligula sodales, sed tempor nisl interdum. Nullam
    et libero elit. In dignissim dignissim pharetra. Proin in ligula a
    erat vehicula mollis. height: 198.000000 2013-09-06 10:34:03.971
    DApp[11370:c07]</p>
  </blockquote>
  
  <p>Creating the cell:</p>
  
  <pre><code>-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {        
      perfilMensagemEnviada *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellMensagemEnviada" forIndexPath:indexPath];
  
      cell.textViewMensagem.text = ([mensagem objectForKey:@"conteudo"] != [NSNull null]) ? [Metodos formatarTexto:[[mensagem objectForKey:@"conteudo"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]] : @"";
  
      cell.imageView.image = self.imagemUsuario;
  
      return cell;
  }
  </code></pre>
  
  <p>Am i forgetting something?</p>
  
  <p><strong>I just just folved my problem! Link below</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/13163834/uicollectionview-showing-wrong-cells-after-scrolling-dequeue-issue?answertab=votes#tab-top">UICollectionView showing wrong cells after scrolling - dequeue issue?</a></p>