开发者

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 f开发者_如何学Cind a good solution to this problem... any suggestions?

Thank you


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];


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 :)


For first section (ziro)

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


Mark Alldritt's answer was good, but sometimes it doesn't size the label correctly. Fixed example is below (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];


Swift 5 Answer

tableView.beginUpdates()

tableView.footerView(forSection: 0)?.textLabel?.text = "Text Here"

tableView.endUpdates()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜