Reputation: 109
I have dynamic cell and dynamic header view for each section in uitableview. Ho de we enable the scroll for header along with tableview cell?
Upvotes: 5
Views: 12094
Reputation: 137
Add double the number of sections you actually have. Let even number of sections only have section headers, while odd number section should have only rows without section headers.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return double the number of sections.
return ([_arrSection count]*2);
}
and..
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//Even Sections will have only header and no rows
if(section%2 == 0)
return 0;
//Number of rows return only is the section is expanded else return 0
return [arrRowsForSpecificSection count];
}
and...
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
//Odd sections will have no header
if(section%2 == 1)
return 0;
//for even sections
return HEIGHT_FOR_SECTION_HEADER;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//Odd section will have no header
if(section%2 == 1)
return NULL;
//even section will have header
return Header_View;
}
Thus at run time it gives an impression that it is the header of current section that scrolls without getting fixed at the top. Smooth animation!!!! Cheers
Upvotes: -2
Reputation: 69
If we have to show same UI approach for iOS 6 & 7 we have use the above in scrollview delegate.
Upvotes: 0