【问题标题】:change cell background更改单元格背景
【发布时间】:2012-02-17 04:22:17
【问题描述】:

如何更改uitableview单元格背景图片?

我写了这段代码,它不起作用。但我确信这段代码有些小错误。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) 
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [cell setBackgroundView:[UIImage imageNamed:@"selected-bg.png"]];
}

【问题讨论】:

标签: iphone objective-c


【解决方案1】:

您需要将UIImage 包装在UIImageView 中,然后才能将其设置为backgroundView

UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected-bg.png"]] autorelease];
[cell setBackgroundView:imageView];

【讨论】:

    【解决方案2】:

    您将不正确的参数传递给UITableViewCellsetBackgroundView: 函数。它期望UIView 的实例或从UIView 继承的任何实例。

    UIImageView * myImage = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected-bg.png"]];
    [cell setBackgroundView:myImage];
    [myImage release];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-14
      • 2011-09-24
      • 2013-04-12
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多