我在我的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