0

テーブルビューを含むアプリを作成しました。そのセルの背景を設定し、セパレーターのビューを追加しています。見た目は問題ありませんが、セパレーターよりもテーブルビューをスクロールすると消えます。このような、

初回 ここに画像の説明を入力 テーブルスクロール時 ここに画像の説明を入力

これはテーブルビューを追加するための私のコードです

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *SimpleTableIdentifier;
    UITableViewCell * cell;

    SimpleTableIdentifier = @"SimpleTableIdentifier";
    cell = [tableView  dequeueReusableCellWithIdentifier: nil];

    if(cell == nil) {

        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:SimpleTableIdentifier];

        // Configure the cell...
        UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
        bgview.opaque = YES;
        bgview.backgroundColor = [UIColor colorWithRed:(224/255.0) green:(230/255.0) blue:(241/255.0) alpha:1];
        [cell setBackgroundView:bgview];

        UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 1)];
        separatorLineView.backgroundColor = [UIColor colorWithRed:(74/255.0) green:(89/255.0) blue:(138/255.0) alpha:1];// you can also put image here
        [cell.contentView addSubview:separatorLineView];
    }
    return cell;
}
4

5 に答える 5

1

使用する

   cell = [tableView  dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

試す

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *SimpleTableIdentifier;
    UITableViewCell * cell;

    SimpleTableIdentifier = @"SimpleTableIdentifier";
    cell = [tableView  dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

    if(cell == nil) {

        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:SimpleTableIdentifier];
        UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 42, 320, 1)];
        [separatorLineView setTag:1];
        [cell.contentView addSubview:separatorLineView];

        UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
        bgview.opaque = YES;
        bgview.backgroundColor = [UIColor colorWithRed:(224/255.0) green:(230/255.0) blue:(241/255.0) alpha:1];
        [cell setBackgroundView:bgview];



    }

    UIView *SPview=[cell viewWithTag:1];
    SPview.backgroundColor = [UIColor blueColor];// you can also put image here

    return cell;
}

問題は、ビューに設定したフレームです。区切り線の原点を 44 から 42 に変更したところ、正常に動作するようになりました。

于 2013-06-10T12:20:34.800 に答える
0

ここで良い答え。

最初に xib ファイルを介してセパレーターを追加し、このコードを cellForRowAtIndexPath に配置します。

tableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 10.0f)] autorelease];
于 2013-06-10T13:21:05.153 に答える
0

セルの構成を外側に移動します

if (cell == nil) {
    cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
}

// everything else

トリックを行う必要があります。

于 2013-06-10T12:21:52.707 に答える