0

カスタマイズしているテーブル ビューがありますが、それを選択すると、半分しか選択されません...見てください:

ハイライトなし

ハイライト

ハイライトなし:

ハイライト:

テーブルビューを制御するクラスからの私のコード:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    // create the parent view that will hold header Label
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)];

    // create image object
    UIImage *myImage = [UIImage imageNamed:@"trolley.png"];;

    // create the label objects
    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:15];
    headerLabel.frame = CGRectMake(70,22,200,20);
    headerLabel.text =  @"Object";
    headerLabel.textColor = [UIColor darkGrayColor];

    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    detailLabel.backgroundColor = [UIColor clearColor];
    detailLabel.textColor = [UIColor redColor];
    detailLabel.text = @"Quantity";
    detailLabel.font = [UIFont systemFontOfSize:15];
    detailLabel.frame = CGRectMake(230,20,230,25);

    // create the imageView with the image in it
    UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
    imageView.frame = CGRectMake(10,10,50,50);

    [customView addSubview:imageView];
    [customView addSubview:headerLabel];
    [customView addSubview:detailLabel];

    return customView;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [lista count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
   return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...

    return cell;
}

あなたが私を理解できることを願っています!

4

1 に答える 1

1

のドキュメントからtableView:viewForHeaderInSection:

... このメソッドは、tableView:heightForHeaderInSection: も実装されている場合にのみ正しく機能します。

したがって、カスタム ヘッダー ビューを定義しますが、テーブル ビュー コントローラーはそれが 60 ポイントの高さであることを知りません。したがって、テーブル ヘッダーは最初のセルと重なっています。

追加する

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    return 60.;
}

助けるべきです。

于 2012-07-29T22:43:32.197 に答える