Xcode (4.4.1) を使用してプログラムで作成された pickerView に 2 つのコンポーネントがあります。
UIPickerView *picker = [[[UIPickerView alloc] init] retain];
[picker sizeToFit];
picker.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
クラッシュした場所はわかっているので、この pickerView に関連するすべてのコードをダンプする必要はないと思います。
pickerView はシミュレーターでは魅力的に機能しますが、iPhone デバイス (5.1.1) でテストするとすぐに、次の方法でクラッシュしました。
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if (component == 0) return [array1 count];
if (component == 1) {
NSLog(@"selectedRowInComponent:%i",[pickerView selectedRowInComponent:1]); //CRASHES HERE
return [[array2 objectAtIndex:[pickerView selectedRowInComponent:1]] count];
}
}
次のエラーが発生しました。
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
私が言ったように、シミュレーターでテストした場合(問題なし)、デバイスでテストした場合(クラッシュ)!!!