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

エラーが発生するため、意味がありません-(UILabel setImage)コードでUIImageViewを明確に使用している場合???

これがデバッガーでnslogされるものです...

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 のストーリーボードまたは nib を確認します。本当に問題がある場合は、見つけやすくするためにプログラムで追跡することもできます。

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 に答える