【发布时间】:2010-12-04 18:03:14
【问题描述】:
我的 UITableView 中有一个自定义部分标题,但我无法弄清楚为什么它们出现在表格的 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;
}
【问题讨论】:
-
您确定
[LojaInfoHeaderView viewHeight]实际上返回了正确的高度而不是返回 0? -
是的,实现是 + (CGFloat)viewHeight { return 44.0; } // 44 是正确的高度。
-
离题:你是如何让导航栏和工具栏以及所有的栏按钮变成可爱的紫色的?你在 iOS 4.x 下运行吗?谢谢。 (不确定获得回复的最佳方式 - 没有直接向您发布问题。)
-
这是导航栏的色调
-
谢谢。这会覆盖“完成”按钮和其他获得“特殊”水蓝色的按钮吗?
标签: iphone objective-c uitableview ios