问题
I want to create expandable table view.
I found one link which is same as I want.

But I want to create my own table view (Dont want to implements this github code).
How do I achieve this type of functionality ?
回答1:
See this nice tutorial: Table View Animations and Gestures
Demonstrates how you can use animated updates to open and close sections of a table view for viewing, where each section represents a play, and each row contains a quotation from the play. It also uses gesture recognizers to respond to user input: * A UITapGestureRecognizer to allow tapping on the section headers to expand the section; * A UIPinchGestureRecognizer to allow dynamic changes to the height of table view rows; and * A UILongPressGestureRecognizer to allow press-and-hold on table view cells to initiate an email of the quotation.
回答2:
I came across similar feature, to build it a rough algorithm will be:
implement the uitableviewdelgate and uitableviewdatasource protocols
create a global variable expandedSectionIndex = -1;
= -1 represents all collapsed.
= 0 represents expandedSectionIndex.
//the following protocol definitions will take care of which section is to be expanded. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(expandedSectionIndex == section) return [self.dataArray[section] count]; else return 0; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if(self.dataArray) return [self.dataArray count]; }
define custom header views in – tableView:viewForHeaderInSection:
- buttons having frame equivalent to header view frame
- set button tag property with value of section number.
associate all buttons with selector - (void)expand:(id) sender;
- (void)expand:(id) sender { expandedSectionIndex = [sender tag]; [self.tableView reload]; }
for more detail enter link description here
来源:https://stackoverflow.com/questions/7568450/iphone-how-to-create-expanadable-table-view