Изменение заголовка/заголовка раздела UITableView без перезагрузки всего вида таблицы
Есть ли способ перезагрузить заголовок/нижний колонтитул таблицы в виде таблицы без вызова
[tableView reloadData];
?
Фактически, я хочу показать количество ячеек в разделе просмотра таблицы в нижнем колонтитуле раздела. Вид таблицы доступен для редактирования, и я удаляю или вставляю строки, используя
– insertRowsAtIndexPaths:withRowAnimation:
– deleteRowsAtIndexPaths:withRowAnimation:
Кажется, что эти методы не обновляют нижний колонтитул раздела. Как ни странно, когда я вызываю эти методы, метод data-source таблицы вида
- (NSString *)tableView:(UITableView *)table titleForFooterInSection:(NSInteger)section
вызывается (дважды!), но он не обновляет представление таблицы новыми значениями!
Кто-нибудь знает, как исправить эту проблему?
Ответы
Ответ 1
Мне удалось сделать это косвенным образом: я создал UILabel и установил его как заголовок/нижний колонтитул раздела.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
// update sectionFooterView.text
return sectionFooterView;
}
- (void)viewDidLoad {
// create sectionFooterView in Interface Builder, change the frame here
// use Font-size:15 , BG-Color: clearColor , text-Color: RGB=(97,105,118)
// and Text-alignment:Center to look like table view original footer
sectionFooterView.frame = CGRectMake(0, 10, 320, 12);
}
Кто-нибудь знает способ сделать это без установки пользовательского представления нижнего колонтитула?
Ответ 2
Если у вас есть только базовый текстовый заголовок или нижний колонтитул, вы можете получить к ним доступ напрямую:
[tableView footerViewForSection:indexPath.section].textLabel.text = [self tableView:tableView titleForFooterInSection:indexPath.section];
аналогично для заголовка:
[tableView headerViewForSection:indexPath.section].textLabel.text = [self tableView:tableView titleForHeaderInSection:indexPath.section];
Ответ 3
Это должно работать:
UIView.setAnimationsEnabled(false)
tableView.beginUpdates()
if let containerView = tableView.footerViewForSection(0) {
containerView.textLabel!.text = "New footer text!"
containerView.sizeToFit()
}
tableView.endUpdates()
UIView.setAnimationsEnabled(true)
Ответ 4
Вот еще один способ сделать это:
UITableViewHeaderFooterView *headerView=[self.tableView headerViewForSection:1];
CATransition *animation = [CATransition animation];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionFade;
animation.duration = 0.35;
[headerView.textLabel.layer addAnimation:animation forKey:@"kCATransitionFade"];
headerView.textLabel.text=[self tableView:self.tableView titleForHeaderInSection:1];
[headerView.textLabel sizeToFit];
Ответ 5
Проверьте документацию для UITableView или, более конкретно,
-reloadSections:withRowAnimation:
Ответ 6
Вот как вы это делаете в Swift 3.0
tableView.beginUpdates()
tableView.headerView(forSection: indexPath.section)?.textLabel?.text = "Some text"
tableView.endUpdates()