2011-10-27 2 views
0

나는 UIPickerView를 가지고있다. 내가 행을 선택하면이 발생합니다SIGABRT 치명적인 오류

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

switch ([defaults integerForKey:@"randomIndex"]) { 
    case 1: 
     switch (component) { 
      case 0: 
       [defaults setInteger:row forKey:@"randomIndex"]; 
       [defaults synchronize]; 
       [colourPicker reloadAllComponents]; 
       [colourPicker selectRow:[defaults integerForKey:@"randomIndex"] inComponent:0 animated:NO]; 
       [colourPicker selectRow:[defaults integerForKey:@"dice1Index"] inComponent:1 animated:NO]; 
       [colourPicker selectRow:[defaults integerForKey:@"dice2Index"] inComponent:2 animated:NO]; 
       [colourPicker selectRow:[defaults integerForKey:@"colourIndex"] inComponent:3 animated:NO]; 
       break; 
      case 1: 
       [defaults setObject:([diceArray objectAtIndex:row]) forKey:@"dice"]; 
       [defaults setInteger:row forKey:@"dice1Index"]; 
       [defaults synchronize]; 
       break; 
      case 2: 
       [defaults setObject:([diceArray objectAtIndex:row]) forKey:@"dice"]; 
       [defaults setInteger:row forKey:@"dice2Index"]; 
       [defaults synchronize]; 
       break; 
      case 3: 
       [defaults setObject:([colourArray objectAtIndex:row]) forKey:@"colour"]; 
       [defaults setInteger:row forKey:@"colourIndex"]; 
       [defaults synchronize]; 
       break; 
     } 
     break; 
    case 0: 
     switch (component) { 
      case 0: 
       [defaults setInteger:row forKey:@"randomIndex"]; 
       [defaults synchronize]; 
       [colourPicker reloadAllComponents]; 
       [colourPicker selectRow:[defaults integerForKey:@"randomIndex"] inComponent:0 animated:NO]; 
       [colourPicker selectRow:[defaults integerForKey:@"dice1Index"] inComponent:1 animated:NO]; 
       [colourPicker selectRow:[defaults integerForKey:@"colourIndex"] inComponent:2 animated:NO]; 
       break; 
      case 1: 
       [defaults setObject:([diceArray objectAtIndex:row]) forKey:@"dice"]; 
       [defaults setInteger:row forKey:@"dice1Index"]; 
       [defaults synchronize]; 
       break; 
      case 2: 
       [defaults setObject:([colourArray objectAtIndex:row]) forKey:@"colour"]; 
       [defaults setInteger:row forKey:@"colourIndex"]; 
       [defaults synchronize]; 
       break; 
     } 
     break; 
} 

}는 iOS 시뮬레이터에서

, 나는 GET 첫 번째로 다시 다음 UIPicker보기에 가서 두 번째 행에 1 열을 변경하는 경우 a SIGABRT 치명적인 오류입니다. 로그는 다음과 같습니다.

2011-10-27 16:02:55.516 Random[31369:b303] *** Terminating app due to uncaught exception  'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 3 beyond bounds [0 .. 2]' 
*** Call stack at first throw: 
(
0 CoreFoundation      0x00dc45a9 __exceptionPreprocess + 185 
1 libobjc.A.dylib      0x00f18313 objc_exception_throw + 44 
2 CoreFoundation      0x00dba0a5 -[__NSArrayM objectAtIndex:] + 261 
3 UIKit        0x0000b750 -[UIPickerView  _selectRow:inComponent:animated:notify:] + 125 
4 UIKit        0x0000b6cd -[UIPickerView selectRow:inComponent:animated:] + 64 
5 Random        0x00004747 -[FlipsideViewController pickerView:didSelectRow:inComponent:] + 855 
6 UIKit        0x0000bc34 -[UIPickerView _sendSelectionChangedForComponent:] + 100 
7 UIKit        0x0000ba15 -[UIPickerView scrollerDidEndSmoothScrolling:] + 75 
8 UIKit        0x001b97c7 -[UIScroller(Internal) _stopScrollingNotify:dealloc:pin:] + 692 
9 UIKit        0x001bb1d0 -[UIScroller(Static) _smoothScroll:] + 4743 
10 UIKit        0x001b1488 ScrollerHeartbeatCallback + 129 
11 GraphicsServices     0x00fff3a3 HeartbeatTimerCallback + 35 
12 CoreFoundation      0x00da58c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19 
13 CoreFoundation      0x00da6e74 __CFRunLoopDoTimer + 1220 
14 CoreFoundation      0x00d032c9 __CFRunLoopRun + 1817 
15 CoreFoundation      0x00d02840 CFRunLoopRunSpecific + 208 
16 CoreFoundation      0x00d02761 CFRunLoopRunInMode + 97 
17 GraphicsServices     0x00ffc1c4 GSEventRunModal + 217 
18 GraphicsServices     0x00ffc289 GSEventRun + 115 
19 UIKit        0x00024c93 UIApplicationMain + 1160 
20 Random        0x00001cb9 main + 121 
21 Random        0x00001c35 start + 53 
22 ???         0x00000001 0x0 + 1 
    ) 
terminate called throwing an exceptionCurrent language: auto; currently objective-c 
(gdb) 

왜 이런 일이 발생합니까?

답변

2

[UIPickerView selectRow:inComponent:animated:]에 대한 호출 중 하나가 시스템에 3 행 (최대 인덱스 : 2) 만있는 열에서 네 번째 항목 (색인 : 3)을 선택하도록 요청하고 있습니다. 코드가 더 이상 나타나지 않으면 이것이 왜 발생하는지 말할 수 없습니다.

0

귀하의 배열은 2로만 인덱스를 가지고 있습니다. 그러나 당신이 행을 선택하면 기존에 존재하지 않는 배열의 3 번째 인덱스 객체에 액세스하려고 시도합니다. 배열 수에 초점을 맞추려고합니다