Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update section footer title in UITableView without reloading

I would like to be able to programmatically update the footer title of a section inside a table view, while I am typing text through a keyboard. The keyboard appears when I click on a cell to make its detailedText view editable, so I would like to update the footer title without reloading from the data source.

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

Thank you

like image 283
marzapower Avatar asked May 08 '11 19:05

marzapower


2 Answers

I know I'm late to this thread, but I've found you can simply do this:

[self.tableView beginUpdates];
[self.tableView footerViewForSection:section].textLabel.text = @"Whatever";
[[self.tableView footerViewForSection:section].textLabel sizeToFit];
[self.tableView endUpdates];
like image 166
Mark Alldritt Avatar answered Oct 24 '22 02:10

Mark Alldritt


If you have groupped 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 via

yourLabel.text = @"whatever you want";

Please check if that works :)

like image 35
akashivskyy Avatar answered Oct 24 '22 02:10

akashivskyy