Friday, June 7, 2013

UITableView tableFooterView example in Objective C (iOS).

UITableView tableFooterView

Returns an accessory view that is displayed below the table.

@property(nonatomic, retain) UIView *tableFooterView

Discussion of [UITableView tableFooterView]
The default value is nil. The table footer view is different from a section footer.

No mater what width you set to the view that you are adding as a table footer/header - its width always will be as the table's width.

UITableView tableFooterView example.
tableFooterView like this:

@property(nonatomic,retain) UIView *tableFooterView;                            // accessory view below content. default is nil. not to be confused with section footer
so the default property is nil. That's why you can't add another UIView to nil UIView. You should do something like this:

controls.tableFooterView = myFooterView;
[myFooterView release];

Example of [UITableView tableFooterView].
    UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)];
    [footerView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"ProductCellBackground.png"]]];
    self.tableView.tableFooterView = footerView;
    [self.tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    [self.tableView setContentInset:(UIEdgeInsetsMake(0, 0, -500, 0))];

UITableView tableFooterView example.
CGRect tvFrame = tableView.frame;
CGFloat height = tvFrame.size.height - tableView.contentSize.height;
if (height > MIN_HEIGHT) { // MIN_HEIGHT is your minimum tableViewFooter height
    CGRect frame = tableFooterView.frame;
    tableFooterView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height);

End of UITableView tableFooterView example article.