Friday, June 7, 2013

UITableView sectionFooterHeight example in Objective C (iOS).


UITableView sectionFooterHeight

The height of section footers in the receiving table view.

@property(nonatomic) CGFloat sectionFooterHeight

Discussion of [UITableView sectionFooterHeight]
This value is used only in section group tables, and only if the delegate doesn't implement the tableView:heightForFooterInSection: method.

UITableView sectionFooterHeight example.
For all who want to shrink the distance to 0 you have to use:

tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;


Because the serving of the UITableViewDelegate does only make an effect starting from floats greater than zero.

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1.0;
}

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

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

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}
(using iOS 4.1 with XCode 4.0.2)

Example of [UITableView sectionFooterHeight].
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    tableView.sectionHeaderHeight = (section == 0 ? 10 : 0); return tableView.sectionHeaderHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
tableView.sectionFooterHeight = (section == 0 ? 20 : 4); return tableView.sectionFooterHeight;
}

UITableView sectionFooterHeight example.
    CGFloat sectionFooterHeight = 40;
    CGFloat tableViewHeight = self.tableView.frame.size.height;

    if (scrollView.contentOffset.y=tableViewHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(0, 0,-scrollView.contentOffset.y, 0);
    } else if (scrollView.contentOffset.y>=sectionFooterHeight+self.tableView.frame.size.height) {
        scrollView.contentInset = UIEdgeInsetsMake(0, 0,-sectionFooterHeight, 0);
    }

End of UITableView sectionFooterHeight example article.