2010-12-04 85 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

試圖改變你的整個表格樣式進行分組,而不是簡單的。或者將您的剖面視圖變爲不透明。無論設計要求如何。