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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With