Update values ​​for a UILabel placed in the header section of UITableViews

I would like my section title to display the sum of the values ​​in my rows. Therefore, I implement:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

delegate the function and put the UILabel in the custom view that I create here.

If it is a UITableViewCell, I would build a cell if it does not exist, then update it or if it exists - update it.

I do not know which "template" to use to update the section title. Or there is a “correct path” in the UITableView, but I can not find “updateSectionHeaderForSection” and only call it when I change the value of the string.

What puzzles me is how the UITableView deals with the headers, does it only call viewForHeadersInSectiononce on reloadData/ instance, or does it call it all the time, i.e. it re-creates the view again when scrolling if I put this code in viewController ?:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

        UIImageView *shadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"topbar.png"]];

}

And how to get the section title to update the view, for example, call updateRowsAtIndexPaths when I change the value it should display?

I can't seem to find Apples in this UITableView programming guide.

Thanks in advance for your help.

+3
source share
1 answer

- , , viewForHeaderInSection. , , , ,

detailLabel.tag=100001;

, , ,

UILabel *total = (UILabel*)[self.view viewWithTag:100001];

:

total.text = @"1234";
0

Source: https://habr.com/ru/post/1765527/


All Articles