Iphone UITableViewCell背景图像未显示

Iphone UITableViewCell背景图像未显示,iphone,ios,uitableview,background-image,Iphone,Ios,Uitableview,Background Image,我正在尝试使用以下代码向UITableViewCell添加背景图像: UIImage *bgImage=[UIImage imageNamed:@"green-cell-row.png"]; UIImageView *bgForFirst=[[UIImageView alloc] initWithImage:bgImage]; cell.backgroundView=bgForFirst; [cell.contentView addSubview:venueDisplayImage]; [cel

我正在尝试使用以下代码向UITableViewCell添加背景图像:

UIImage *bgImage=[UIImage imageNamed:@"green-cell-row.png"];
UIImageView *bgForFirst=[[UIImageView alloc] initWithImage:bgImage];
cell.backgroundView=bgForFirst;
[cell.contentView addSubview:venueDisplayImage];
[cell.contentView addSubview:venueDisplayName1];
[cell.contentView addSubview:venueDisplayName2];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
但是,我在它周围的空白处看到了venueDisplayName。修复此问题并正确添加背景图像的最佳方法是什么?

您是否尝试将backgroundColor或venueDisplayName更改为[UIColor clearColor]或[UIColor greenColor]

出于性能原因,请尽量避免在UITableViewCell中使用非不透明视图。

请尝试以下方法:

1选项卡视图将背景设置为:

tblView.backgroundView.alpha = 0.0;
tblView.backgroundColor=[UIColor clearColor];
2在tableview的cellForRowAtIndexPath og委托方法中添加图像视图:

UIImageView *bckView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 300,80)];
cell.backgroundView.alpha = 0.0;
cell.backgroundColor=[UIColor clearColor];
bckView.image = [UIImage imageNamed:@"cell.png"];
bckView.contentMode = UIViewContentModeScaleToFill;
[cell.contentView addSubview:bckView];

您必须使用cell的属性 有两个属性可以使用 1.背景色 2.背景视图

    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageName:@""]];

在第二种情况下,您必须将任何视图设置为背景视图

没有venueDisplayName是UILabel,我用一个框架初始化它,然后将它添加到单元格中