objective-c – viewForHeaderInSection:调用reloadData:时不
发布时间:2020-12-16 10:34:38 所属栏目:百科 来源:网络整理
导读:我创建了一个UITableView并设置了“delegate”和“datasource”,每次调用reloadData时,它都会进入方法: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return [self.headersList count];} 方法: -(NSInteger)tableView:(UITableVie
我创建了一个UITableView并设置了“delegate”和“datasource”,每次调用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,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; } 解决方法
您应该实现heightForHeaderInSection:并将标头的高度设置为值> 0.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |