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];
原文地址:http://www.cnblogs.com/goodheart/p/3998734.html