У меня есть UITableView
в моем приложении (Swift, но я объясняю этот пример в Objective- c. Я загружаю в это viewForHeaderInSection
пользовательское представление, но у этого представления есть динамические c элементы, зависящие от размера.
По умолчанию я загружаю короткий заголовок, а затем меняю его на 6 с небольшим текстом, но затем 6 секунд, когда текст меняется, размер заголовка не изменяется.
Если я загружаю текст в первый раз, это меняет размер содержимого, но мне нужно установить этот текст затем на 6 секунд вместо первого. Я пытаюсь с UITableViewAutomaticDimension
, но footerView
не изменяет размер с моим кодом.
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"SampleCell" bundle:nil] forCellReuseIdentifier:@"SampleCell"];
[self.tableView registerNib:[UINib nibWithNibName:@"SampleHeader" bundle:nil] forHeaderFooterViewReuseIdentifier:@"SampleHeader"];
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionHeaderHeight = 10;
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
SampleHeader *header = (SampleHeader * )[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"SampleHeader"];
header.label.text = @"Section 1. It has a short title.";
double delayInSeconds = 6.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
header.label.text = @"Section 3. It has a extra large title, the view will grow to addapt follwoing the autolayout constraints that we have set in the interface builder tra large title, the view will grow to addapt follwoing the autolayout constraints that we h tra large title, the view will grow to addapt follwoing the autolayout constraints that we h tra large title, the view will grow to addapt follwoing the autolayout constraints that we h tra large title, the view will grow to addapt follwoing the autolayout constraints that we h";
[header layoutIfNeeded];
});
return header;
}
Как правильно перезагрузить заголовок раздела , после чего будет загружен tableView? Спасибо!