2

テーブルビューの背景を自分の画像でカスタマイズしたい 私は以下のコードを使用してセルの背景ビューをカスタマイズしています

-(void)tableView:(UITableView *)tableView
 willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
    NSInteger rowIndex = indexPath.row;
    UIImage *background = nil;

    if (rowIndex == 0) {
        background = [UIImage imageNamed:@"TableTopBackground.png"];
    } else if (rowIndex == rowCount - 1) {
        background = [UIImage imageNamed:@"TableBottomBackground.png"];
    } else {
        background = [UIImage imageNamed:@"TableMiddleBackground.png"];
    }

    [cell setBackgroundView:[[UIImageView alloc]initWithImage:background]];

}

私の問題は、ios5で実行すると下部のセル画像と中央のセル画像が交換されることです(画像1)が、ios6では問題ありませんでした(画像2)。

iOS 5 イメージ

iOS 6 イメージ

しかし、背景色を設定すると、ios5とios 6の両方でうまく機能していました。

cellForRowatindexpath にコードを記述しても機能しますが、なぜ willdisplaycell で機能しないのですか。

ありがとうございました

4

1 に答える 1

1

メソッドにimage 入れて追加cellForRowAtIndexPath

    cell.backgroundView.backgroundColor = [UIColor colorWithPatternImage:image];

このコードは

if(cell == nil)
 {
 }
于 2013-03-28T12:26:55.863 に答える