我做了一个UITableView
,并设置了“委托”和“数据源”每次我打电话reloadData
时,它进入方法:viewForHeaderInSection:不调用时reloadData:被称为
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.headersList count];
}
而且方法:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
SectionInfo *headerInfo = (self.headerInfoArray)[section];
NSInteger numOfObjectsInSection = [[headerInfo.list objectsInList] count];
return headerInfo.open ? numOfObjectsInSection : 0;
}
然后停下来!它不会进入ViewForHeaderInSection:
方法。我也实施方法:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return SECTION_HEADER_HEIGHT;
}
- 知道我使用打开/关闭部分功能!所以首先关闭所有部分,每个部分的行数是0,但返回的部分数是正确的(当部分被打开时,行数被更新)。
- 它显示标题视图的唯一方法是等待一段时间,直到它自动重新加载!或者我向上或向下滑动!
的viewForHeaderInSection
方法:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UISectionHeaderView *sectionHeaderView = [[UISectionHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, SECTION_HEADER_HEIGHT)];
SectionInfo *sectionInfo = (self.headerInfoArray)[section];
sectionHeaderView.open = sectionInfo.open;
sectionInfo.headerView = sectionHeaderView;
sectionHeaderView.titleLabel.text = [NSString stringWithFormat:@"%@ (%lu)",sectionInfo.list.title, (unsigned long)[sectionInfo.list.objectsInList count]];
sectionHeaderView.section = section;
sectionHeaderView.delegate = self;
return sectionHeaderView;
}
我假设你设置你的类都是'dataSource'和''UITableView'的'delegate',对吧? – dasblinkenlight
您也可以使用重载部分方法尝试不同的方法。向我们展示您的表视图页眉和页脚视图数据源回调,以查看是否存在问题。 – J2theC
呀,dataSource和delegate没有错。这种行为只发生在所有部分都关闭时。 – a7md