【问题标题】:UITableViewCell: image appears behind the Cell ViewUITableViewCell:图片出现在 Cell View 后面
【发布时间】:2012-01-11 22:13:17
【问题描述】:

它真的很烦人,但由于某种原因,我的 ImageView 出现在单元格视图的后面。如果我关闭剪辑,那么我可以在单元格后面看到图像。仅供参考,我正在尝试显示从照片库中挑选并转换为 PNG 的图像。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    static NSString *headerCellID = @"FormHeaderCellView";
    if(indexPath.section==0 && indexPath.row==0) //Header cell
    {
        FormHeaderCellView *cell = (FormHeaderCellView *)[self.tableView dequeueReusableCellWithIdentifier:headerCellID];

        if (cell == nil)
        {
            NSArray *topLevelObjects =[[NSBundle mainBundle] loadNibNamed:headerCellID owner:nil options:nil];

            for (id currentObject in topLevelObjects) 
            {
                if( [currentObject isKindOfClass:[UITableViewCell class]])
                {
                    cell = (FormHeaderCellView *) currentObject;
                    break;
                }
            }

        }


        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *file = [documentsDirectory stringByAppendingPathComponent:@"logo.png"];

        if([[NSFileManager defaultManager] fileExistsAtPath:file])
        {   
            UIImage *img=[[UIImage alloc] initWithContentsOfFile:file];

            [cell.logoImage setImage:img];
        }


        [cell.textLabel setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"userName"]];

        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        return cell;

    }

一切似乎都加载得很好,因为我可以直观地看到单元格后面的图像。 非常感谢您的帮助。

更新:做了一些测试,如果在我设置的笔尖中,图像看起来很好 logoImage 的图像属性到捆绑包中的任何图像。所以问题在于显示从文档目录加载的图像(从照片库保存)。

【问题讨论】:

  • 你在哪里为 cell.logoImage 创建框架?
  • FormHeaderCellView 是 UITableViewCell 的子类,而 logoImage 是 IBOutlet UIImageView 属性。在 NIB 中,我已经很好地连接了连接。
  • 在 NIB 中确保 logoImage 高于一切。
  • 是的,徽标图像在顶部。
  • 我不明白你想做什么和你得到什么,如果你仍然有兴趣解决这个问题,我将不胜感激。

标签: iphone xcode uitableview uiimageview


【解决方案1】:

我附近没有 Mac,因此对于代码中的任何错误,我深表歉意。

您确定 logoImage 高于其他视图吗?在您的单元格中尝试执行以下操作:

[self.view addSubview:self.logoImage];
[self.view bringSubviewToFront:self.logoImage];

这应该将您的 logoView 放在单元格的所有其他子视图之上。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-18
    • 2018-10-09
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多