Saturday, June 8, 2013

UITableView tableView heightForFooterInSection example in Objective C (iOS).


UITableView tableView heightForFooterInSection

Asks the delegate for the height to use for the footer of a particular section.

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

Parameters
tableView
The table-view object requesting this information.
section
An index number identifying a section of tableView .

Return Value of [UITableView tableView heightForFooterInSection]
A floating-point value that specifies the height (in points) of the footer for section.

Discussion of [UITableView tableView heightForFooterInSection]
This method allows the delegate to specify section footers with varying heights. The table view does not call this method if it was created in a plain style (UITableViewStylePlain).

Special Considerations
Prior to iOS 5.0, table views would automatically resize the heights of footers to 0 for sections where tableView:viewForFooterInSection: returned a nil view. In iOS 5.0 and later, you must return the actual height for each section footer in this method.

UITableView tableView heightForFooterInSection example.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  if (![section hasRow]) return 0;
}
and

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  if (![section hasRow]) return 0.0f;
}

Example of [UITableView tableView heightForFooterInSection].
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
        return 6;
    return 1.0;
}

-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    return 5.0;
}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}

UITableView tableView heightForFooterInSection example.
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    switch (section) {
        case 7:
            return 80;
    }
    return 10;
}

End of UITableView tableView heightForFooterInSection example article.