How to force uitableview to resize a cell (after deactivating a height constraint)?
<p>I am trying to put an extendable <code>UITableViewCell</code> by tapping on a button.</p>

<p>I am using the constraints to force the dynamic <code>UITextView</code> to tell the <code>UITableViewCell</code> the its new height. (using autolayout and <code>UITableViewAutomaticDimension</code>)</p>

<p>This works as expected without the button: The height of the <code>UITableViewCell</code> depends on the <code>UITextView</code>'s height. </p>

<p>Having a constraint on the <code>UITextView</code> to maximize the size of the cell, when tapping the button (the cell is collapsed), I want to remove height constraint to the <code>UITextView</code> (that is limiting the cell height) and update the cell accordingly. Here's the extend method: </p>

<pre><code>-(void)extendCellWasTapped:(UITableViewCell*)senderCell{

    MAFollowingPostTableViewCell *cell = (MAFollowingPostTableViewCell*)senderCell;

    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

    if (![self.arrayExtendedTitlesAtIndexPaths containsObject:indexPath]) {
        [self.arrayExtendedTitlesAtIndexPaths addObject:indexPath];
    }

    if ([self.tableView.indexPathsForVisibleRows containsObject:indexPath] ) {
        dispatch_async(dispatch_get_main_queue(), ^(void){

            [NSLayoutConstraint deactivateConstraints:@[cell.constraintTextViewHeight]];

           // CGPoint offset = self.tableView.contentOffset;

            [self.tableView beginUpdates];
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableView endUpdates];

// I would like to minimize the animations as well here.. but thats another //problem
//            [self.tableView.layer removeAllAnimations];
//            [self.tableView setContentOffset:offset animated:NO];
//            [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

        });
    }
}
</code></pre>

<p>If I tap the button and then scroll to a similar cell, it is already expanded. So I am missing something here. I already tried to do <code>[cell updateConstraints]</code> after deactivating the constraint, but it doesn't work. </p>

<p><strong>UPDATE</strong></p>

<p>At first, the button doesn't show up for some reason. And I noticed that (with the same code) if I scroll down and then up, the button shows up and, if I try to extend it, it works.</p>

<p><strong>UPDATE</strong></p>

<p>This is my UIViewController :</p>

<p><a href="http://www.gfycat.com/FairBossyAfricanporcupine" rel="nofollow noreferrer">http://www.gfycat.com/FairBossyAfricanporcupine</a></p>

<p>Notice that the extend button is not there, but once I scroll down/up it comes shows up and it extends the cell once I tap on the extend button. </p>

<p><strong>UPDATE</strong></p>

<p>I noticed that when the textSize is being calculated (to see if the cell is extendable or not), at first, the textView is wider than its final state. And I am performing this check on the cellForRowAtIndexPath : </p>

<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

MAPostTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier forIndexPath:indexPath];

cell.delegate = self;
cell.selectionStyle = UITableViewCellSelectionStyleNone;

MAPostFollowing *post = (MAPostFollowing*)[self.arrayPosts objectAtIndex:indexPath.section];

cell.textViewTitle.textContainer.lineBreakMode = NSLineBreakByWordWrapping;

NSString *title = [post.post title];

[cell.textViewTitle setText:title];

UIButton * buttonExtend = [cell buttonExtend];

if ([self.arrayExtendedTitlesAtIndexPaths containsObject:indexPath]) {
    cell.constraintTextViewHeight.active = NO;

    if (![buttonExtend isHidden]) {
        buttonExtend.hidden = YES;
        buttonExtend.userInteractionEnabled = NO;
    }
}else{

    cell.constraintTextViewHeight.active = YES;

    NSLog(@"index %li", (long)indexPath.row);

    BOOL b = ![self isTitleExtendable:title forTextView:cell.textViewTitle]; // Checks if the current text view is able to fit the title. If not, it will show the buttonExtend

    buttonExtend.hidden = b;
    buttonExtend.userInteractionEnabled = !b;

}
}
...
</code></pre>

<p>So on the first run (before scrolling) the [self isTitleExtendable:title forTextView:cell.textViewTitle]; does not return the desired value as the textView doesn't have the right width when the textSize is being calculated. </p>

<p>So I believe have the following options : 
- force the textViewTitle to refresh after it has changed the layout (thus calculating correctly the extendable UI state)
- recheck the extendable UI state once the textViewTitle changes the width</p>

<p><strong>UPDATE</strong></p>

<p>On the method prepareForReuse the textViewTitle still has a wider frame. On the layoutSubviews method it has in fact a small frame. The challenge here is that is gets called more often, and it gets me false cases (button being shown when it shouldn't) </p>

<p>This is what I was experimenting with : </p>

<pre><code>-(void)layoutSubviews{
[super layoutSubviews];

BOOL b = [self isTitleExtendable:self.textViewTitle.text forTextView:self.textViewTitle];

self.buttonExtend.hidden = !b;
self.buttonExtend.userInteractionEnabled = b;

if (!b) {
    NSLog(@"Button hidden YES UserInteraction NO");
}else{
    NSLog(@"Button hidden NO UserInteraction YES");
}

NSLog(@"textViewTitle layout %f",self.textViewTitle.frame.size.width);
}
</code></pre>