Reputation: 1345
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.
Upvotes: 8
Views: 6999
Reputation: 719
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
.
Upvotes: 12