UITableViewCell height animation when selected

Possible duplicate:
Can you change the height change to a UITableViewCell when selected?

I did a lot of Googling to try and figure out the right way to do this, and still am at a loss.

I have subclassed the UITableViewCell with my own view, and I'm trying to animate the height of the UITableViewCell to expand when it is selected, and compress when it is selected again. This table can contain thousands of rows, so I don't want to override tableView heightForRowAtIndexPath. Ideally, I would like to be able to expand several cells at a time, but this is not so important. What is the best way to do this?

Thanks Justin

+5
source share
1 answer

There is no other mechanism for determining cell height than heightForRowAtIndexPath. If you do not properly account for the extended cell in this method, you will find that your other cells either run through it or hide under it. From the bone code where I forgot to set heightForRowAtIndexPath, I am sure that your other cells will be displayed above it.

Since you are talking about thousands of rows, we will assume that the user cannot reorder the cells.

What you can do is keep the extended index path of the cell when the user deletes the given cell. Then heightForRowAtIndexPath might look like this:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{

if ([indexPath isEqual:lastSelectedIndexPath])
{
    return 80;
}

else {
    return 44;
}

}

If you really need several options, you can save the corresponding index paths to an array and check them as follows:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{

CGFloat cellHeight = 44;

for (NSIndexPath *expandedIndexPath in expandedIndexPathsArray)
{
    if ([indexPath compare:expandedIndexPath] == NSOrderedSame)
    {
        cellHeight = 80;
        break;
    }
}

return cellHeight;

}

, . UI . , , - , , .

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPathswithRowAnimation:(UITableViewRowAnimation)animation

, , .

, .

, , , . .

+6

All Articles