Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table view cell expandable iOS

I want a table view with only cels, and when you click on a cell it should expand and show more info of the clicked cell.

I've seen quite some topics on this, but the most of them are linking to Table View Animations and Gestures on the apple developer page. Which does it in a different way. They use header sections, but I want to use the cell which is expandable for layout reasons.

I already tried several things mainly with

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

    if (isSearching && indexPath.row == selectedIndex) {
        return 110;
    }
    else {
        return rowHeight;       
    }

When I Click on the cell, the cell is expanded but the info in that cell stays the same. Also the heigth of the cell when expanded should be related to the amount of text in the details.

Thnx!

like image 722
peter Avatar asked Apr 05 '11 09:04

peter


People also ask

How do you expand a cell in Swift?

Go to your storyboard, select the tableView that has the cell you need, for the subclass of TableViewCell you need (probably CustomTransactionTableViewCell , in your case). Now select the cell in the TableView (check that you selected the right element.


1 Answers

You can achieve this through the use of custom cells. Create two custom cells, one for the normal row and other for the expanded row. When the user touches a particular cell, you can record it's indexPath and reload the tableView. While reloading you can change the height of this selected row using the code that you've just posted(increasing the height of only the selected cell). This would give an effect of expanding cell.

like image 116
Vin Avatar answered Sep 29 '22 07:09

Vin