Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to expand or collapsed the table view header and if i click on header other header are collapse. please send me the code or useful links to me....
Posted

Have a look at this sample code: Table View Animations and Gestures[^].
 
Share this answer
 
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.

//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]; 
}

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;
// this event will select the expanded section
- (void)expand:(id) sender {
expandedSectionIndex = [sender tag];
[self.tableView reload];
}


[edit]code block added[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900