2

グループ化されたセルに独自のセクション ヘッダーを作成しようとしています。次のコードを使用して作成すると、境界が外れているように見えます。より具体的には、CGRect

ここに画像の説明を入力

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *header = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 50)] autorelease];
    [header setBackgroundColor:[UIColor clearColor]];

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width, 18)] autorelease];
    label.textColor = [UIColor redColor];
    label.text = @"SOME TEXT";
    label.backgroundColor = [UIColor clearColor];

    [header addSubview:label];

    return header;
}

高さがずれている理由は何か分かりますか?何か不足していますか?

4

2 に答える 2

3

tableView:heightForHeaderInSection:ドキュメントに記載されているとおりに実装しましたか? これにより、テーブルに対して 50 が返されます。

于 2012-02-27T21:30:42.200 に答える
0

TableView タイプ (Grouped) を定義せず、IB でセクション ヘッダーのプロパティを設定してから、以下を使用しない理由に興味があります。

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
于 2012-02-27T21:27:54.030 に答える