zoukankan      html  css  js  c++  java
  • 将从数组中取到的字符串赋值给了UIImage导致的错误

      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];

      

      

  • 相关阅读:
    html-Notes3
    html-Notes2 表单
    html 笔记
    网页设计常用色彩搭配表
    css
    html-Notes
    C# 输入字符串,每3个截取一次,形成一个数组
    提高情商的好书推荐 (程序猿不仅要智商也要情商)
    PHP 学习笔记---基本语法
    php学习笔记之字符串处理
  • 原文地址:https://www.cnblogs.com/goodheart/p/3998734.html
Copyright © 2011-2022 走看看