I am having a difficult time figuring out why my UITableViewCell wont animate the contentView when unselected.
I have made some code that will expand and collapse a cell, but somehow when collapsing the cell, it animates the height, but not the contentView. Actually it seems that the contentView is removed.
For the record I have a UILabel added to the contentView. When expanding, the UILabel's frame will resize accordingly, but when collapsing the UILabel is just dismissed or hidden without animations.
Any advice?
Here is some sample code:
/* Expanding and collapsing code */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self cellIsSelected:indexPath])
{
//Item is clicked, unclick it
[self.selectedIndexes removeObject:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
else
{
//Item is not clicked. Deselect others and select this
[self.selectedIndexes removeAllObjects];
[self.selectedIndexes addObject:indexPath];
}
[tableView beginUpdates];
[tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self cellIsSelected:indexPath]) {
return 150;
}
return [tableView rowHeight];
}