Iphone UITableView自定义节标题显示在单元格下方
我的UITableView中有一个自定义的节标题,我不明白为什么它们出现在表的UITableView单元格下面。请参见屏幕截图: 这是创建节标题的代码:Iphone UITableView自定义节标题显示在单元格下方,iphone,objective-c,uitableview,ios,Iphone,Objective C,Uitableview,Ios,我的UITableView中有一个自定义的节标题,我不明白为什么它们出现在表的UITableView单元格下面。请参见屏幕截图: 这是创建节标题的代码: - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:se
- (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];
}
当用户触摸节标题时,将插入或删除节的单元格:
- (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;
}
+(CGFloat)视图高度{
回报率44.0;
}
+(LojaInfoHeaderView*)LojainFoheaderSection:(NSInteger)节,节标题:(NSString*)标题已打开:(BOOL)等参和委派:(id)委派{
LojaInfoHeaderView*newHeader=[[LojaInfoHeaderView alloc]initWithFrame:CGRectMake(0,0320,44)]自动删除];
newHeader.section=节;
[新标题集标题:标题];
newHeader.delegate=委托;
[newHeader setOpen:isOpen动画:否];
返回newHeader;
}
尝试将整个表格样式改为分组而不是普通。或者将剖面视图更改为不透明。无论设计要求是什么。尝试将整个桌子样式改为分组,而不是普通的。或者将剖面视图更改为不透明。无论设计要求是什么。我发现了问题。我用alpha设置背景色(是的,我不敢相信我错过了这个)
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];
我发现了问题。我用alpha设置背景色(是的,我不敢相信我错过了这个) 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];
你确信
[LojaInfoHeaderView viewHeight]
实际上返回了正确的高度,而没有返回0吗?是的,实现是+(CGFloat)viewHeight{return 44.0;}//并且44是正确的高度。离题:你是如何让导航栏、工具栏和所有的栏按钮都具有可爱的紫色的?您是否在iOS 4.x下运行?谢谢(不确定获得回复的最佳方式-没有直接向您发布问题。)这是一个彩色导航栏,谢谢。这是否覆盖了“完成”按钮和其他获得“特殊”水蓝色的按钮?您是否确定[LojaInfoHeaderView viewHeight]
实际上返回了正确的高度而没有返回0?是的,实现是+(CGFloat)viewHeight{return 44.0;}//和44是正确的高度。离题:你是如何让导航栏、工具栏和所有的栏按钮都变成可爱的紫色的?您是否在iOS 4.x下运行?谢谢(不确定获得回复的最佳方式-没有直接向您发布问题。)这是一个彩色导航栏,谢谢。这会覆盖“完成”按钮和其他获得“特殊”水蓝色的按钮吗?在initWithFrame中设置self.不透明=是不会解决问题。至于使用分组样式,我不明白为什么这会是一个解决方案,因为设计很重要,而且它使节标题不会粘住,这不是我所需要的。您可以尝试将其设置为表标题视图,而不是节标题视图,这可能会解决问题。可以,但我有多个节,在屏幕截图中,我只显示了一个。但是这个问题发生在所有的节上。我看到你的函数是类函数,而不是类的实例,你能发布一些关于如何创建节头的代码吗?这将有助于更好地理解创建过程谢谢,现在我明白了self.opaque=YES不起作用的原因。因为您只能在类的实例中使用self,而不能在类函数本身中使用self。尝试在LojaInfoHeaderView类的实例上调用.opaque=YES,该类是您在ViewForHeaderInstruction函数中创建的,即在您的节头类上添加一个指针,即LojaInfoHeaderView*头=[LojaInfoHeaderView LojainFoheaderSection…];header.不透明=是;返回头;看看这是否有帮助。在initWithFrame中设置self.opaque=YES无法解决问题。至于使用分组样式,我不明白为什么这会是一个解决方案,因为设计很重要,而且它使节标题不会粘住,这不是我所需要的。您可以尝试将其设置为表标题视图,而不是节标题视图,这可能会解决问题。可以,但我有多个节,在屏幕截图中,我只显示了一个。但是这个问题发生在所有的节上。我看到你的函数是类函数,而不是类的实例,你能发布一些关于如何创建节头的代码吗?这将有助于更好地理解创建过程谢谢,现在我明白了self.opaque=YES不起作用的原因。因为您只能在类的实例中使用self,而不能在类函数本身中使用self。尝试在LojaInfoHeaderView类的实例上调用.opaque=YES,该类是您在ViewForHeaderInstruction函数中创建的,即在您的节头类上添加一个指针,即LojaInfoHeaderView*头=[LojaInfoHeaderView LojainFoheaderSection…];header.不透明=是;返回头;看看这是否有帮助。嗯,这个可能很难猜:)嗯,这个可能很难猜:)