Refresh section footer in UITableView without rebooting

I would like to be able to programmatically update the section footer header inside the table view while I type text from the keyboard. The keyboard appears when I click on a cell to make its detailed view editable, so I would like to update the footer header without rebooting from the data source.

In fact, if I did, the keyboard would disappear, so this is not a good form of interaction. I could not find a good solution to this problem ... any suggestions?

thanks

+6
source share
4 answers

If you come across a table, you can use:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 17)]; //I'm not sure about the frame... yourLabel.font = [UIFont systemFontOfSize:16]; yourLabel.shadowColor = [UIColor whiteColor]; yourLabel.shadowOffset = CGSizeMake(0, 1); yourLabel.textAlignment = UITextAlignmentCenter; yourLabel.textColor = RGB(76, 86, 108); yourLabel.backgroundColor = [UIColor clearColor]; yourLabel.opaque = NO; return yourLabel; } 

Declare yourLabel in your .h file. Then you can access it through

 yourLabel.text = @"whatever you want"; 

Please check if this works :)

+6
source

I know I was late for this topic, but I found that you can just do this:

 [self.tableView beginUpdates]; [self.tableView footerViewForSection:section].textLabel.text = @"Whatever"; [[self.tableView footerViewForSection:section].textLabel sizeToFit]; [self.tableView endUpdates]; 
+6
source

For the first section (ziro)

[self.tableView footerViewForSection: 0] .textLabel.text = @ "test";

+1
source

Mark Aldritt’s answer was good, but sometimes he doesn’t correctly label the tag. The example below is fixed (for section == 0):

 [self.tableView beginUpdates]; UILabel *footerLabel = [self.tableView footerViewForSection:0].textLabel; footerLabel.text = [self tableView:self.tableView titleForFooterInSection:0]; CGRect footerLabelFrame = footerLabel.frame; footerLabelFrame.size.width = self.tableView.bounds.size.width; footerLabel.frame = footerLabelFrame; [self.tableView endUpdates]; 
+1
source

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


All Articles