2012-06-25 74 views
1

我用調試器和突破點,以針點下來哪一行代碼,我收到,我會告訴你的錯誤...[的UILabel setImage:]:無法識別的選擇發送到實例

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的我的代碼?

這裏是獲取調試nsloged ...

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) 
+1

僅僅因爲你強烈地將一個對象輸入爲'UIImageView',它並不意味着它是一個。你的'viewWithTag:'方法正在返回一個不響應'setImage'的UILabel,就這麼簡單。您需要確保您的UIImageView子視圖被正確標記和唯一標記。目前你可能有一個UILabel和一個UIImageView,這兩個標籤的值都是相同的(我的猜測是它們都是== 0) – Rog

回答

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]; 
相關問題