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

I add a header and footer when creating my table. I want to change the contents of the footer dynamically and programmatically. Is there a standard way to get a UIView for a footer?

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

+7
source share
1 answer

You can tag your custom section footer when creating it, for example, in tableView:viewForFooterInSection: for example:

 mySectionFooterView.tag = kMySectionFooterViewTag; 

kMySectionFooterViewTag can be any NSInteger you like.

To access mySectionFooterView from any other part of your program, you can use:

 mySectionFooterView = [myTableView viewWithTag:kMySectionFooterViewTag]; 

myTableView is a UITableView that includes your custom footer section. You can usually use myTableView as self.tableView when using the UITableViewController .

Note that performance considerations may arise with this approach, as viewWithTag: will look for the entire hierarchy of myTableView .

+12
source

All Articles