我在我的UITableView中有一个自定义节标题,我无法弄清楚为什么它们出现在表的UITableViewCell的下方。看屏幕截图:UITableView自定义节标题出现在单元格下面
这是创建节头中的代码:
- (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;
}
你肯定是`[LojaInfoHeaderView viewHeight]`真的返回了正确的高度,而不是返回0? – imaginaryboy 2010-12-04 18:10:57
是的,实现是+(CGFloat)viewHeight {return 44.0; } //和44是正确的高度。 – 2010-12-04 18:22:36
偏题:你如何获得导航栏和工具栏以及所有酒吧按钮,以获得可爱的紫色?你在iOS 4.x下运行吗?谢谢。 (不知道获得回应的最佳方式 - 发布问题的时间短。) – westsider 2010-12-04 18:33:29