2010-12-04 6 views
1

私のUITableViewにカスタムセクションヘッダーがあり、なぜそれらが表のUITableViewCellに表示されているのかわかりません。これは、セクションヘッダを作成するコードであるUITableViewのカスタムセクションヘッダーがセルの下に表示される

UITableViewCell are above the section header

- (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]; 
} 

とセクションのセルが挿入または削除されているスクリーンショットを見ます

セクションヘッダーをセルの上に表示するにはどうすればよいですか?それを修正するには?

更新物事は

これらは、私が使用しているクラスメソッドです作成する方法を示すために:

+ (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

ていますか? – imaginaryboy

+0

はい、実装は+(CGFloat)viewHeight {return 44.0; } //と44は正しい高さです。 –

+0

トピックオフ:どのようにナビバーとツールバーとすべてのバーボタンが素敵な紫色を持つようになっていますか? iOS 4.xで動作していますか?ありがとう。 (回答を得るための最善の方法は不明 - あなたに向けられた質問の投稿が不十分です) – westsider

答えて

0

問題が見つかりました。私はアルファを使ってbackgroundColorを設定していました(ええ、これが間違っているとは信じられません)。 initWithFrameで

間違っコード:

self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]; 

正しいコード:あなたは `[LojaInfoHeaderView viewHeight]`実際に正しい高さを返すと0を返していないことを肯定

self.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.0]; 
+0

まあ、これは推測するのが難しいかもしれない:) –

0

を無地のではなく、グループ化するためにあなたの全体の表スタイルを変更しようとします。または、セクションビューを不透明に変更します。デザイン要件は何でもあります。

+0

initWithFrameのself.opaque = YESを設定しても解決しませんでした。グループ化されたスタイルを使用しているとき、私はなぜこれが解決策になるのか分かりません。なぜなら、デザインが重要なので、セクションヘッダーが私に必要なものではないからです。 –

+0

あなたはテーブルヘッダービューではなくセクションヘッダービューとして設定しようとすることができますが、これで解決できるかもしれません。 –

+0

ありますが、複数のセクションがあり、スクリーンショットでは1つしか表示されていません。しかし、この問題はすべてのセクションで発生します。 –