Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access footer or header view of specific section in UITableView?

I add header and footer view while creating my table. What I want to do is to change the content of the footer dynamically and programmatically. Is there a standard way to get the UIView for footer?

I know there is a way which is to add a UIView property and assign the foot UIView while it is created in - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section but I would like to know whether there is a better way to do this.

like image 206
Alexander Huang Avatar asked Jun 18 '11 15:06

Alexander Huang


People also ask

How do I scroll the header along with UITableView?

If you have a single header in the table then you can use tableHeaderView as below: tableView. tableHeaderView = Header; Or if you have multiple header in table than you need to use Group table instead of plain table.


1 Answers

You could tag your custom section footer view when you create it, e.g., in tableView:viewForFooterInSection:, like this:

mySectionFooterView.tag = kMySectionFooterViewTag;

kMySectionFooterViewTag can be any NSInteger you like.

To access mySectionFooterView from some other part of your program you can then use:

mySectionFooterView = [myTableView viewWithTag:kMySectionFooterViewTag];

myTableView is the UITableView that includes your custom section footer view. You can typically access myTableView as self.tableView, when using a UITableViewController.

Note that there can be performance considerations with this approach, because viewWithTag: will search the entire view hierarchy of myTableView.

like image 154
Spiros Avatar answered Nov 18 '22 11:11

Spiros