iOS 7 UItableview单元格背景视图

问题描述:

我正在使用图像视图作为tableview单元格背景视图。当我在xcode 4.x中编译我的源代码时,它工作正常,即在iOS 6.x和7.0中都能正常工作。但是,当我编译我的源代码在Xcode 5.0,背景图像视图没有出现的iOS 7iOS 7 UItableview单元格背景视图

任何想法,为什么它不工作? iOS 7中的uitableview单元格背景视图有没有限制?

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:accountProfileTypeCell]; 
    UIImageView *cellBgView =[[UIImageView alloc]init]; 
    [cellBgView setImage:[UIImage imageNamed:@"cellBgView.png"]]; 
    [cell setBackgroundView:cellBgView]; 
} 
+0

你是如何设置背景的?显示您正在使用的实际代码。 –

+0

我已添加code.Thanks – Techie

+0

[UIImage imageImaged:] imageImaged不是在UIImage类中的任何方法。它的 - imageNamed。请在你的代码 – iProgrammer

尝试添加:cell.backgroundColor = [的UIColor clearColor];

+0

是它的工作谢谢 – Techie

试试这个。它适用于我

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:accountProfileTypeCell]; 
UIView *cellBgView =[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [cell frame].size.width, [cell frame].size.height)]; 
[cellBgView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBgView.png"]]]; 
[cell setBackgroundView:cellBgView]; 
+0

'VActivityStreamBack'? –

+0

VActivityStreamBack?我可以知道这是什么吗?谢谢 – Techie

+0

我已经从我的应用程序中的一个“VActivityStreamBack”复制了这段代码,但不幸的是我错过了替换。而已。 –

唯一缺少的是将框架设置为cellBgView。设置图像不会调整imageView的大小。但是,如果您使用initWithImage初始化imageView,它将调整imageView的大小以适应图像。

+0

我认为,我们没有必要为背景views.Thanks设定框架 – Techie

+0

是的,如果你使用backgroundView由小区不是你初始化了一个初始化。 –

你只需要在您的ImageView申请自动调整大小。

如果您的ImageView被应用到整个屏幕。为其分配所有边距。

结帐图像

您必须设置在willDisplayCell的背景。下面的代码是一样的你唯一的是,移动它在willDisplay方法

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

    if(cell.backgroundView==nil){ 
     UIImageView *cellBgView =[[UIImageView alloc]init]; 
     [cellBgView setImage:[UIImage imageNamed:@"cellBgView.png"]]; 
     [cell setBackgroundView:cellBgView]; 
    } 
} 
+1

它不是必需的,我们只能在显示单元的方法做到这一点,我们可以做到这一点在cellforrow方法本身,我犯了这个错误并没有设置的tableview单元格颜色,清除颜色 – Techie