2016-08-18 6 views
0

私は4つのセクションを持つテーブルビューで作業しています。セクションごとにヘッダービューを実装しました。 tableviewstylePlainとすると正しく動作します。私がtableviewstyleGroupedとすると、それは有線に見えます。iOSでtableviewスタイルがグループ化されていると、セクション内のヘッダーの表示が正しく表示されない理由

これは私がtableviewデリゲートメソッドを実装する方法です。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 4; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section == 0) 
    { 
     return 1; 
    } 
    else if(section == 1) 
    { 
     return 1; 
    } 
    else if (section == 2) 
    { 
     return 3; 
    } 
    else 
    { 
     return 1; 
    } 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, 50)]; 
    UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, screenSize.width-80, 50)]; 

    if (section == 0) 
    { 
     titlelabel.text = @"Flight Summary"; 
     [headerView addSubview:titlelabel]; 
     return headerView; 
    } 
    else if(section == 1) 
    { 
     titlelabel.text = @"Price Summary"; 
     [headerView addSubview:titlelabel]; 
     return headerView; 
    } 
    else if (section == 2) 
    { 
     titlelabel.text = @"Traveller Details"; 
     [headerView addSubview:titlelabel]; 
     return headerView; 
    } 
    else 
    { 
     titlelabel.text = @"Book Now"; 
     [headerView addSubview:titlelabel]; 
     return headerView; 
    } 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"checkcell"]; 
    return cell; 
} 

私がイメージにPlain

enter image description here

リンクとしてテーブルビュースタイルを使用する場合、これはスクリーンショットです:私はGrouped

としてテーブルビュースタイルを使用する場合 image with plain style

が、これはスクリーンショットです

enter image description here

画像へのリンク:image with grouped stye

私はこれであなたの助けを期待し、何が起こっているか見当がつかない。

+0

なぜこれだけで、あなたが'のtableViewを実装しました 'Grouped'のテーブルビュースタイル –

+0

ために起こるのですか? – rmaddy

+0

いいえ私は実装しませんでした。なぜなら私は 'Plain'スタイルを使用していて、そのメソッドを必要としなかったからです。 @rmaddy –

答えて

1

セクションヘッダーの高さを設定する必要があります。以下の方法で試してみてください。 heightForHeaderInSection:: `メソッド

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
return 50 
} 
+0

ありがとう、ありがとう –

関連する問題