【问题标题】:NSCFConstantString size trying to set an ImageNSCFConstantString 大小尝试设置图像
【发布时间】:2013-08-11 13:17:46
【问题描述】:

我正在制作一个 UITableView,每个单元格都有一个 UIIMage。 为了为每个单元格设置不同的图像,我在项目中加载了所有图像并创建了一个包含所有图像_flagsArray = [NSArray arrayWithObjects: @"flag_Italia.png", @"flag_USA", nil]; 的数组。

cellForRowAtIndexPath我写了

UIImageView * flagImageView = (UIImageView *) [self.view viewWithTag:1]; //declaration of UIImageView in cell
UIImage * flagImage = (UIImage *)[_flagsArray objectAtIndex:indexPath.row]; //read UImage
[flagImageView setImage : flagImage]; //should assign UImage to UIImageView

运行它时出现日志*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString size]: unrecognized selector sent to instance 0xcbdc' 崩溃,第三行出现信号 SIGABRT 但我不明白为什么,出了什么问题?

谢谢!

【问题讨论】:

    标签: uitableview uiimageview uiimage nscfstring


    【解决方案1】:

    您的数组包含字符串而不是图像。此外,您似乎正试图从self.view 获取图像视图,而您应该从cell 获取图像视图。这样做:

    UIImageView *flagImageView = (UIImageView *)[cell viewWithTag:1];
    NSString *imageName = _flagsArray[indexPath.row];
    UIImage *flagImage = [UIImage imageNamed:imageName];
    flagImageView.image = flagImage;
    

    或者更简洁:

    UIImageView *flagImageView = (UIImageView *)[cell viewWithTag:1];
    flagImageView.image = [UIImage imageNamed:_flagsArray[indexPath.row]];
    

    【讨论】:

      猜你喜欢
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-13
      • 1970-01-01
      相关资源
      最近更新 更多