Ben Lefebvre
Ben Lefebvre

Reputation: 379

UITableView expander animation

I would like to create a kind of expander (like in .net) animation. I have a UITableView filled with an array. When I touch a row I would like to show a UIView (or a SubView i guess) that would expand under the row cell.

Is it possible to achieve this? I've looked at most of the animation UIView setAnimation Transition but none of them would fit my needs.

Thanks for your help!

Oh by the way, I am running Xcode 4.3.3 on Mac os x 10.7.4. Targeted device for now is iPhone 5.1

Upvotes: 0

Views: 373

Answers (1)

KDaker
KDaker

Reputation: 5909

I haven't seen the .net expander but you can achieve this effect with UITableViews. You can put the View you would like to expand in a cell in a separate section (lets call it section B). You then would hide the cell by setting numberOfRowsInSection: to return 0 for section B.

when you want to show the View, you would set a flag or boolean to make numberOfRowsInSection: return 1 for section B and then call reloadSections:withRowAnimation: to reload section B. Note if you set the row animation to UITableViewRowAnimationTop you would achieve the expander effect..

EDIT:

for hiding the cells in the section you can do it this way:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (section == 2) {//assume 2 is section B

        if (showExpandedView)  //ShowExpandedView is a BOOL you would use to 
            return 1;          //to trigger the expanded view.
        else
            return 0;
    }      
    ...
}

Hope this helps

Upvotes: 2

Related Questions