我在Objective C中遇到崩溃未捕获异常'NSRangeException',原因:'*** __boundsFail:索引3超出范围[0 .. 2]'
这一行的 crashlytics 问题“label.text = [_addressTypeArray objectAtIndex:row];”
如果可能,请参阅下面的代码和帮助
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
**- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (isStateButtonClicked == YES) {
return _stateTypeArray.count;
} else
return _addressTypeArray.count;
}
#pragma mark - UIPickerViewDelegate
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = [[UILabel alloc]init];
label.textColor = [UIColor blackColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont fontWithName:kGothamMediumFontName size:17.0];
if (isStateButtonClicked == YES) {
NSString *stateName = [NSString stringWithFormat:@"%@ - %@", [[_stateTypeArray objectAtIndex:row] objectForKey:@"StateName"], [[_stateTypeArray objectAtIndex:row] objectForKey:@"StateFullName"]];
label.text = stateName;
}
else {
label.text = [_addressTypeArray objectAtIndex:row];
}
return label;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView == self.addressTypePickerView)
{
self.addressTypePickerView.hidden = NO;
orderPickerContainerView.hidden = NO;
disableView.hidden = NO;
if (isStateButtonClicked == YES) {
self.stateRow = row;
self.stateTypeSelected = [[_stateTypeArray objectAtIndex:row] objectForKey:@"StateName"];
} else {
self.addressTypeRow = row;
self.addressTypeSelected = [_addressTypeArray objectAtIndex:row];
}
}
if (pickerView == self.stateTypePickerView)
{
self.stateRow = row;
self.stateTypeSelected = [[_stateTypeArray objectAtIndex:row] objectForKey:@"StateName"];
}
[self.addressTypePickerView reloadAllComponents];
self.scrollViewMain.contentSize = CGSizeMake(self.bounds.size.width, 550.0);
}