【问题标题】:iOS 7 UItableview cell background viewiOS 7 UItableview 单元格背景视图
【发布时间】:2013-09-28 06:46:32
【问题描述】:

我使用图像视图作为表格视图单元格背景视图。当我在 xcode 4.x 中编译我的源代码时,它运行良好,即在 iOS 6.x 和 7.0 中它运行良好。但是当我在 xcode 5.0 中编译我的源代码时,背景图像视图没有出现在 iOS 7 中。

任何想法,为什么它不起作用? 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];
}

【问题讨论】:

  • 你是如何设置背景的?显示您正在使用的实际代码。
  • 我已经添加了代码。谢谢
  • [UIImage imageImaged: ] imageImaged 不是 UIImage 类中的任何方法。它的-imageNamed。请在您的代码中编辑它
  • 对不起,我在粘贴这段代码时犯了这个错误,但我在 xcode 中正确编写了代码
  • 你可以尝试添加:cell.backgroundColor = [UIColor clearColor];

标签: iphone ios objective-c ios7


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您必须在 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];
        }
    }
    

    【讨论】:

    • 不需要只在will display cell方法中做,可以在cellforrow方法本身做,我犯的错误是没有设置tableview cell color为clear color
    【解决方案3】:

    试试这个。这对我有用

     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];
    

    【讨论】:

    • VActivityStreamBack?
    • VActivityStreamBack ??我可以知道这是什么吗?谢谢
    • 我已经从我的一个应用程序中复制了这段代码,它是“VActivityStreamBack”,不幸的是我错过了替换它。就是这样。
    【解决方案4】:

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

    【讨论】:

    • 我认为,我们不需要为背景视图设置框架。谢谢
    • 是的,如果您使用由单元格初始化的 backgroundView 而不是您初始化的那个。
    【解决方案5】:

    您只需要在您的图像视图中应用自动调整大小。

    如果您的图像视图应用于整个屏幕。为其分配所有边距。

    查看图片

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 2011-09-13
      • 1970-01-01
      • 2013-06-09
      • 1970-01-01
      相关资源
      最近更新 更多