Iphone [UILabel setImage:]:发送到实例的选择器无法识别

Iphone [UILabel setImage:]:发送到实例的选择器无法识别,iphone,objective-c,ios,xcode,cocoa-touch,Iphone,Objective C,Ios,Xcode,Cocoa Touch,我已经使用了调试器和断点来确定我收到错误的代码行,我将在该代码行上向您显示 for (NSString *s in golferFourIconCounter) { if(s != nil) { int sint = [s intValue]; switch (sint) { case 1: iconNum = @"Num1.png";

我已经使用了调试器和断点来确定我收到错误的代码行,我将在该代码行上向您显示

for (NSString *s in golferFourIconCounter) {

        if(s != nil) {
            int sint = [s intValue];
            switch (sint) {
                case 1:
                    iconNum = @"Num1.png";
                    break;
                case 2:
                    iconNum = @"Num2.png";
                    break;
                case 3:
                    iconNum = @"Num3.png";
                    break;
                case 4:
                    iconNum = @"Num4.png";
                    break;
                case 5:
                    iconNum = @"Num5.png";
                    break;
                case 6:
                    iconNum = @"Num6.png";
                    break;
                case 7:
                    iconNum = @"Num7.png";
                    break;
                case 8:
                    iconNum = @"Num8.png";
                    break;
                case 9:
                    iconNum = @"Num9.png";
                    break;

                default:
                    break;
            }

            switch (ids) {
                case 0:
                    imageTitle = @"GolfEagle.jpg";
                    break;
                case 1:
                    imageTitle = @"Birdie.png";
                    break;
                case 2:
                    imageTitle = @"Par.png";
                    break;
                case 3:
                    imageTitle = @"Bogey.png";
                    break;
                case 4:
                    imageTitle = @"Double-Bogey.png";
                    break;
                case 5:
                    imageTitle = @"Triple-Bogey.png";
                    break;
                case 6:
                    imageTitle = @"GolfSandie.png";
                    break;
                case 7:
                    imageTitle = @"Greenie.png";
                    break;
                case 8:
                    imageTitle = @"Polie.png";
                    break;
                case 9:
                    imageTitle = @"Dart.png";
                    break;
                case 10:
                    imageTitle = @"Three-Jack.png";
                    break;
                case 11:
                    imageTitle = @"Arnie.png";
                    break;
                case 12:
                    imageTitle = @"Ladie.png";
                    break;
                case 13:
                    imageTitle = @"Barkie.png";
                    break;
                case 14:
                    imageTitle = @"Hole-In-One.png";
                    break;
                case 15:
                    imageTitle = @"Fairway.png";
                    break;
                default:
                    break;
            }

            iid = iid+41;

            NSLog(@"%d --- %@",iid, iconNum);
            [(UIImageView*)[self.view viewWithTag:iid] setImage:[UIImage imageNamed:iconNum]];

            iid = iid-41;
            int rr = 401900;
            rr++;
            rr = rr+iid;

            [(UIImageView*)[self.view viewWithTag:rr] setImage:[UIImage imageNamed:imageTitle]];
            iid++;
        }

        ids++;
    }
代码在此特定代码行失败。。。(接近for循环的末尾)

这没有任何意义,因为当我在代码中清楚地使用UIImageView时,会出现错误-(UILabel setImage)

以下是在调试器中记录的内容

2012-06-24 21:41:58.518 Dot Golf Scoring[2811:15203] 57 --- (null)
2012-06-24 21:41:58.519 Dot Golf Scoring[2811:15203] 58 --- (null)
2012-06-24 21:41:58.520 Dot Golf Scoring[2811:15203] 59 --- (null)
2012-06-24 21:41:58.522 Dot Golf Scoring[2811:15203] 60 --- (null)
2012-06-24 21:41:58.549 Dot Golf Scoring[2811:15203] 61 --- (null)
2012-06-24 21:41:58.561 Dot Golf Scoring[2811:15203] 62 --- (null)
2012-06-24 21:41:58.562 Dot Golf Scoring[2811:15203] 63 --- (null)
2012-06-24 21:41:58.563 Dot Golf Scoring[2811:15203] 64 --- (null)
2012-06-24 21:41:58.564 Dot Golf Scoring[2811:15203] 65 --- (null)
2012-06-24 21:41:58.565 Dot Golf Scoring[2811:15203] 66 --- (null)
2012-06-24 21:41:58.566 Dot Golf Scoring[2811:15203] 67 --- (null)
2012-06-24 21:41:58.567 Dot Golf Scoring[2811:15203] 68 --- (null)
2012-06-24 21:41:58.567 Dot Golf Scoring[2811:15203] 69 --- (null)
2012-06-24 21:41:58.568 Dot Golf Scoring[2811:15203] 70 --- (null)
2012-06-24 21:41:58.569 Dot Golf Scoring[2811:15203] 71 --- (null)
2012-06-24 21:41:58.569 Dot Golf Scoring[2811:15203] -[UILabel setImage:]: unrecognized selector sent to instance 0x7f98b30
2012-06-24 21:41:58.570 Dot Golf Scoring[2811:15203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel setImage:]: unrecognized selector sent to instance 0x7f98b30'
*** First throw call stack:
(0x153b022 0x30e2cd6 0x153ccbd 0x14a1ed0 0x14a1cb2 0xcbcd 0xabce 0x1c4a1e 0x1cd9bc 0x1c8818 0x3e4565 0x1cb857 0x1cb9bc 0x1cb9fc 0x533f4a 0x5284d0 0x153ce99 0x10014e 0x33ea0e 0x153ce99 0x10014e 0x1000e6 0x1a6ade 0x1a6fa7 0x1a6266 0x1253c0 0x1255e6 0x10bdc4 0xff634 0x16ceef5 0x150f195 0x1473ff2 0x14728da 0x1471d84 0x1471c9b 0x16cd7d8 0x16cd88a 0xfd626 0x288d 0x27f5 0x1)
terminate called throwing an exception(lldb) 

我会检查你的故事板或笔尖上是否有标签71或72的UILabel。如果您确实遇到了问题,您还可以通过编程追踪,以便更容易找到:

UILabel *labelToChange = (UILabel *)[self.view viewWithTag:71];
labelToChange.backgroundColor = [UIColor greenColor];
当你这么做的时候,为什么不把第一个大的长开关换成一个简单的一行呢

if (sint > 0 && sint < 10) iconNum = [NSString stringWithFormat:@"Num%d.png", sint];
if(sint>0&&sint<10)iconNum=[nsstringwithformat:@“Num%d.png”,sint];

仅仅因为您将一个对象强输入为一个
UIImageView
并不意味着它就是一个。您的
viewWithTag:
方法返回的UILabel不响应
setImage
,就这么简单。您需要确保UIImageView子视图被适当且唯一地标记。目前,您可能有一个UILabel和一个UIImageView,它们都具有相同值的标记(我猜它们都==0)
if (sint > 0 && sint < 10) iconNum = [NSString stringWithFormat:@"Num%d.png", sint];