我发现想重用HeaderView,在刷新tableview的时候不要使用reloadSections刷新,要不然HeaderView得不到重用,每次都会创建新的实例,使用reloadData可以解决此问题
- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
if(section ==0) {
XTQuestionStemHeaderView*questionStemHeaderView = (XTQuestionStemHeaderView*)[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
if(!questionStemHeaderView) {
questionStemHeaderView = [[XTQuestionStemHeaderView alloc] initWithReuseIdentifier:@"headerView"]; questionStemHeaderView.backgroundColor=self.baseTable.backgroundColor;
WS(weakSelf)
[questionStemHeaderView setHeightBlock:^(CGFloat height) {
weakSelf.questionStemHeaderViewHeight= height;
// [weakSelf.baseTable reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
[weakSelf.baseTable reloadData];
}];
}
questionStemHeaderView.height = self.questionStemHeaderViewHeight?self.questionStemHeaderViewHeight:40;
questionStemHeaderView.content=_questionName;
returnquestionStemHeaderView;
}
}
网友评论