I came across similar feature, to build it a rough algorithm will be:
1. implement the uitableviewdelgate and uitableviewdatasource protocols
2. create a global variable expandedSectionIndex = -1;
= -1 represents all collapsed.
>= 0 represents expandedSectionIndex.
- (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];
}
2. 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];
}
[edit]code block added[/edit]