【问题标题】:image not showing in a custom uitableviewcell imageview in ipad图像未显示在 ipad 的自定义 uitableviewcell 图像视图中
【发布时间】:2013-11-18 05:23:09
【问题描述】:

我有一个自定义 UITableViewCell 然后我有一个 UIImageView 里面。我可以使用相同的代码在 iphone 和应用程序的其他部分设置它的图像 ..和相同的 customcell ..但是我在某些部分没有显示图像。 以下是未显示部分的示例代码。

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

    static NSString *CellIdentifier = @"CellIdentifier";

    ItemsCell *cell = (ItemsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
//        cell = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        NSArray *nib;
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            nib = [[NSBundle mainBundle] loadNibNamed:@"ItemsCell" owner:self options:nil];
        }
        else
        {
            nib = [[NSBundle mainBundle] loadNibNamed:@"ItemsCell_Ipad" owner:self options:nil];
        }

        cell = [nib objectAtIndex:0];
    }

    cell.titleLabel.text = [miscFileNameArray objectAtIndex:indexPath.row];
    cell.artistLabel.text = [miscSizeArray objectAtIndex:indexPath.row];

    if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        cell.thumbnailImgView.image = [UIImage imageNamed:@"ext_default.png"];
    }
    else
    {
        cell.thumbnailImgView.image = [UIImage imageNamed:@"ipad_ext_defaul.png"];

        NSLog(@"%@",cell.thumbnailImgView.image);
    }

    return cell;
}

当我记录 cell.thumbnailImgView.image 时,它​​会记录图像。但它仍然没有显示。在 iPhone 上它的工作我不知道为什么它不能在 iPad 上工作。

【问题讨论】:

  • 您传递的图片名称是否正确?检查您的应用程序包中是否有使用此名称的图像ipad_ext_defaul.png
  • 尝试为 iPad 记录 cell.thumbnailImgView 的边界,以确保它的大小不为零,或者不在屏幕某处。
  • 使用断点并检查您的图像或图像名称是否正确??
  • 是的,图像名称是正确的,我已经对其进行了三次检查,它还在构建阶段的复制包资源中添加。我真的不知道为什么它不起作用我在另一个类中使用了相同的代码。
  • @rdelmar 我尝试记录 NSLog(@"cell:%f",cell.thumbnailImgView.bounds.origin.x);它说 0.0000 所以它意味着它在某个地方。我该怎么办

标签: ios objective-c uitableview uiimage


【解决方案1】:

有两种可能:

  • 选择时检查是否正在加载ItemsCell_Ipad iPad。表示它正在加载正确的单元格。
  • 第二个也是最有可能的是自定义单元格中的连接,我 认为您忘记与 iPad 中的图像视图建立连接。

【讨论】:

  • 我尝试在它的加载 ItemsCell_Ipad 中放置一个断点,连接也正确我已经检查过了,在另一个类中我已经使用了这个代码并且它可以工作。我真的不知道为什么它在这个上不起作用。
【解决方案2】:

首先检查“ipad_ext_defaul.png”是否在您的资源文件夹中。(名称必须与您在代码中给出的名称相同) 如果它在资源文件夹中,则从您的 iPad 中删除应用程序。清理您的构建并重新安装。

您一定会找到您的解决方案。

祝你好运!!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多