时间: 2020-11-22|31次围观|0 条评论

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

      NSArray * imageArr = @[@"tabbar_limitfree",
                           @"tabbar_reduceprice",
                           @"tabbar_appfree",
                           @"tabbar_subject",
                           @"tabbar_rank"];

   [item setImage:imageArr[i] forState:UIControlStateNormal]; //这行代码具有迷惑性,titleArr[i]是取出来的数据类型是 id ,实际上取到值是NSString类型的。因为OC是运行时语言,所以编译时,编译器会觉得它是对的,但是到了运行的时候,发现它并没有想要的方法,所以报了经典错误 unrecognized selector sent to instance。

  改正后的代码:

    [item setImage:[UIImage imageNamed:imageArr[i]] forState:UIControlStateNormal];

 

  

  

转载于:https://www.cnblogs.com/goodheart/p/3998734.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/95114227

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《将从数组中取到的字符串赋值给了UIImage导致的错误
   

还没有人抢沙发呢~