加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读