2010-12-04 82 views
1

我在我的UITableView中有一个自定义节标题,我无法弄清楚为什么它们出现在表的UITableViewCell的下方。看屏幕截图:UITableView自定义节标题出现在单元格下面

UITableViewCell are above the section header

这是创建节头中的代码:

- (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; 
} 
+0

你肯定是`[LojaInfoHeaderView viewHeight]`真的返回了正确的高度,而不是返回0? – imaginaryboy 2010-12-04 18:10:57

+0

是的,实现是+(CGFloat)viewHeight {return 44.0; } //和44是正确的高度。 – 2010-12-04 18:22:36

+0

偏题:你如何获得导航栏和工具栏以及所有酒吧按钮,以获得可爱的紫色?你在iOS 4.x下运行吗?谢谢。 (不知道获得回应的最佳方式 - 发布问题的时间短。) – westsider 2010-12-04 18:33:29

回答

0

我发现了这个问题。我使用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]; 
0

试图改变你的整个表格样式进行分组,而不是简单的。或者将您的剖面视图变为不透明。无论设计要求如何。