title: Expand UILabel inside UITableView with "more" button like Instagram
body: <p>I've got a project (that has been written by other people) where there's a feed with content and text displayed inside a table view. Each post corresponds to one section in table view, and each section has its own rows corresponding to elements like content, text, like button etc.</p>
  
  <p>I need to display a short label for post captions with a "more" button inside table view cell, and when more button is tapped, the label will expand to whatever size the caption fits, all happening inside a table view cell. When the more button is tapped I change the label's <code>numberOfLines</code> property to zero, and as the cells have automatic height, all I need is to reload that particular caption cell. (the cell displays correctly with the expanded size if I set <code>numberOfLines</code> to 0 at the first place before displaying the cell.)</p>
  
  <p>I've tried:</p>
  
  <p><code>[tableView beginUpdates];</code>
  <code>tableView endUpdates];</code></p>
  
  <p>I've tried various animation options with:</p>
  
  <p><code>[tableView reloadRowsAtIndexPaths:@[myPath] withRowAnimation:UITableViewRowAnimation(Bottom,Top,None etc)];</code></p>
  
  <p>I've tried:</p>
  
  <p><code>[tableView reloadSections:[NSIndexSet indexSetWithIndex:myPath.section] withRowAnimation:UITableViewRowAnimation(Top,Bottom,None etc)];</code></p>
  
  <p>But they all yield the same result: the whole table view layout gets messed up: it jumps to another cell, some views go blank, cells overlap each other, video inside cells stop playing, and the label doesn't expand (but refreshes inside itself, e.g. that short preview txt with one line animates from top/bottom etc but doesn't expand).</p>
  
  <p>What might be causing the mess up of the whole table view and how I can reload just one cell correctly with and expansion animation, without messing up the whole layout? I've seen many questions and answers regarding this, but they all recommend the options that I've already tried and explained above.</p>
  
  <p>My app targets iOS 8.0+</p>
  
  <p><strong>UPDATE:</strong> Here is the relevant code (with some parts regarding inner workings that aren't related to layout, removed):</p>
  
  <pre><code>MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier: MyCellIdentifier forIndexPath:indexPath];
  cell.delegate = self;
  cell.indexPathToReloadOnAnimation = indexPath;
  cell.shouldShortenCaption = YES;
  
  id post = self.posts[indexPath.section] ;
  [cell setPost:post];
  
  return cell;
  </code></pre>
  
  <p>And inside <code>setPost:</code>:</p>
  
  <pre><code>if(self.shouldShortenCaption){
      captionLabel.numberOfLines = 2;
  }else{
      captionLabel.numberOfLines = 0;
  }
  NSString *text = [some calculated (deterministic) text from post object];
  </code></pre>
  
  <p>Button action is simple:</p>
  
  <pre><code>self.shouldShortenCaption = NO;
  [one of the reload codes that I've written above in the question]
  </code></pre>
  
  <p><strong>UPDATE 2:</strong> Here are some more methods regarding the issue:</p>
  
  <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
      if (section &lt; self.posts.count) {
          return 59;
      }else
          return 0;
  }
  
  - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
      if (section &lt; self.posts.count) {
          MyFeedHeader *header = [tableView dequeueReusableCellWithIdentifier:MyFeedHeaderIdentifier];
          header.delegate = self;
          [header setPostIndex:section];
          [header setPost:self.posts[section]] ;
  
          return header;
      }
      else
          return nil;
  }
  </code></pre>
  
  <p>Header's <code>setPost:</code> method basically sets the relevant texts to labels (which have nothing to do with the caption, they are completely different cells. the problematic cell is not the header cell). The table doesn't have any footer methods. The only method regarding height is the one above.</p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      if (section &gt;= self.posts.count) {
          return 1;
      }
      id post = self.posts[section];
      [calculate number of rows, which is deterministic]
      return [number of rows];
  }
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      BOOL hasCursor = self.cursor &amp;&amp; self.hasMore ? 1 : 0;
      return self.posts.count + hasCursor;
  }
  </code></pre>
  
  <p>(Post count and cursor and hasMore are also deterministic).</p>
  
  <p><strong>UPDATE 3:</strong> I've asked a question (which wasn't a duplicate, even though there are similar questions) and got a useful answer that solved my problem. Can the downvoters please elaborate the reason that they've downvoted?</p>