Friday, June 7, 2013

UITableView setTableFooterView example in Objective C (iOS).

UITableView setTableFooterView

Returns an accessory view that is displayed below the table.

@property(nonatomic, retain) UIView *tableFooterView

Discussion of [UITableView setTableFooterView]
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 setTableFooterView 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 setTableFooterView].
    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 setTableFooterView example.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, 0)];
v.backgroundColor = [UIColor clearColor];
[tableView setTableHeaderView:v];
[tableView setTableFooterView:v];
return v;

End of UITableView setTableFooterView example article.