繁体   English   中英

UITableView自定义节标题出现在单元格下方

[英]UITableView custom section header appears below the cells

我的UITableView中有一个自定义节标题,我不知道为什么它们出现在表的UITableViewCell之后。 看截图:

UITableViewCell在节标题上方

这是创建节标题的代码:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }

    return [LojaInfoHeaderView lojaInfoHeaderForSection:section withTitle:sectionTitle opened:[self sectionIsOpen:section] andDelegate:self];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return [LojaInfoHeaderView viewHeight];
}

用户触摸节标题时,将插入或删除节的单元格:

- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidOpen:(NSInteger)section {
    NSArray *indexPathsToInsert = [self indexPathsForSection:section];
    [self setSection:section open:YES];
    [_tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationTop];
}

- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidClose:(NSInteger)section {
    NSArray *indexPathsToDelete = [self indexPathsForSection:section];
    [self setSection:section open:NO];
    [_tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];    
}

如何使节标题显示在单元格上方? 如何解决?

更新以显示事物的创建方式

这些是我正在使用的类方法:

+ (CGFloat)viewHeight {
    return 44.0;
}

+ (LojaInfoHeaderView *)lojaInfoHeaderForSection:(NSInteger)section withTitle:(NSString *)title opened:(BOOL)isOpen andDelegate:(id<LojaInfoHeaderDelegate>)delegate {
    LojaInfoHeaderView *newHeader = [[[LojaInfoHeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
    newHeader.section = section;
    [newHeader setTitle:title];
    newHeader.delegate = delegate;
    [newHeader setOpen:isOpen animated:NO];
    return newHeader;
}

尝试将整个表格样式更改为分组形式,而不是普通形式。 或将剖面视图更改为不透明。 无论设计要求是什么。

我发现了问题。 我正在使用alpha设置backgroundColor(是的,我不敢相信我会错过这一点)。

initWithFrame中的代码错误:

self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];

正确的代码:

self.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.0];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM