1

我已经使用调试器和断点来确定我收到错误的代码行,我将向您展示...

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*)[self.view viewWithTag:iid] setImage:[UIImage imageNamed:iconNum]];

这没有任何意义,因为当我在代码中明确使用 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) 
4

1 回答 1

2

我会检查您的情节提要或笔尖以查找带有标签 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];
于 2012-06-25T02:03:06.520 回答