UITableView 映像导致崩溃



我已经做了一百万个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 = [[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'

这样做:

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

您存储的是图像的名称,而不是图像。但是,imageView 将 UIImage 作为其属性,而不是图像名称。因此,请进行以下更改。

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

最新更新