0

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

Ben Lefebvre
  • 359
  • 5
  • 21
  • Do you want to cover up the rows beneath or push them down? I know how to do it either way – jacerate Jul 13 '12 at 16:02
  • 1
    Possible duplicate of [Expand/collapse section in UITableView](http://stackoverflow.com/questions/1938921/expand-collapse-section-in-uitableview) – Max MacLeod Nov 03 '15 at 08:49

1 Answers1

2

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

KDaker
  • 5,899
  • 5
  • 31
  • 44
  • Thanks a lot mate, this will be of great help :) – Ben Lefebvre Jul 13 '12 at 17:01
  • i suppose i would do something like if(indexpath.section == "B") return 0; or something along those lines in order to have both sections return different number of rows from the same method – Ben Lefebvre Jul 13 '12 at 17:26