【问题标题】:UITableView image causes crashUITableView 图像导致崩溃
【发布时间】:2012-06-28 11:22:17
【问题描述】:

我已经完成了一百万个 UITables - 带有字幕、图像、背景、颜色、文本样式 - 随便你说。 突然,我在这张桌子上崩溃了,特别是在需要细胞图像的那一行。 代码如下:

// Configure the cell:
cell.textLabel.font = [UIFont fontWithName:@"Franklin Gothic Book" size:18];
cell.textLabel.text = [leadershipMenu objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [leadershipSubtitlesMenu objectAtIndex:indexPath.row];

// And here's the statement that causes the crash:
cell.imageView.image = [leadershipPhotosMenu objectAtIndex:indexPath.row];

现在,我得到的错误是:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0xcacbc'

我确定导致崩溃的语句是

cell.imageView.image = ...

因为一旦我将其注释掉,一切正常。

我这辈子都没见过

-[__NSCFConstantString _isResizable]: 

错误。 我已经用谷歌搜索了它,但发现很少。

非常奇特。

有人知道线索吗?

【问题讨论】:

  • 什么是leadershipPhotosMenu?它是一组图像吗?
  • 您是如何将图像存储在“leadershipPhotosMenu”数组中的?我可以看看它是什么吗?
  • 当然,这是代码:leadershipPhotosMenu = [[NSMutableArray alloc] initWithObjects:@"JohnQ.jpg", @"BillZ.png", nil]; 这些图像在我的项目中 - 意味着它们在 Xcode 中,是捆绑包的一部分。

标签: iphone uitableview uiimageview uiimage


【解决方案1】:

如您的评论中所述。您保存图像的方式是导致问题的原因。

试试这个..

leadershipPhotosMenu = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"JohnQ.jpg"], [UIImage imageNamed:@"BillZ.png"], nil];

上面的代码会将图像存储在您的 mutableArray 中,这会起作用,但我建议不要将图像存储在数组中。

您也可以解决您的问题,而无需像上面的代码那样将图像存储在数组中:

cell.imageView.image = [UIImage imageNamed:(NSString*)[leadershipPhotosMenu objectAtIndex:indexPath.row]];

此错误消息意味着您的 leadershipPhotosMenu 中的对象不是图像,而是字符串

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0xcacbc'

【讨论】:

  • 耶稣 - 总脑放屁。显然已经连续盯着屏幕太多小时了。在这个项目中,我有 40 个带有图像的表格,我看不到这个简单的错误盯着我的脸。显然是时候打麻袋了 :-) 谢谢孩子们! (抱歉)
【解决方案2】:

这样做:

 cell.imageView.image = [UIImage imageNamed:[leadershipPhotosMenu objectAtIndex:indexPath.row]];

【讨论】:

  • 正确,这是您可以遵循的另一种选择。
【解决方案3】:

您存储的是图片广告的名称,而不是图片。然而 imageView 有 UIImage 作为它的属性,而不是图像名称。所以进行以下更改。

cell.imageView.image = [UIImage imageNamed:[leadershipPhotosMenu objectAtIndex:indexPath.row]];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多