Iphone Uipicker在同时旋转两个部件时崩溃
下面的代码创建了一个崩溃,如果我同时旋转两个组件,有时根据选择的数组,这些值将超出范围 我需要一些条件检查,这将停止碰撞,但不知道如何 有人能建议合适的代码来处理这种情况以避免崩溃吗 谢谢Iphone Uipicker在同时旋转两个部件时崩溃,iphone,uipicker,Iphone,Uipicker,下面的代码创建了一个崩溃,如果我同时旋转两个组件,有时根据选择的数组,这些值将超出范围 我需要一些条件检查,这将停止碰撞,但不知道如何 有人能建议合适的代码来处理这种情况以避免崩溃吗 谢谢 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ // Only calls the following code if compon
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
// Only calls the following code if component "0" has changed.
if (component == 0)
{
// Sets the global integer "component0Row" to the currently selected row of component "0"
component0Row = row;
// Loads the new values for the selector into a new array in order to reload the data.
NSDictionary *newDict = [[NSDictionary alloc]initWithDictionary:[pickerData objectForKey:[Letters objectAtIndex:component0Row]]];
NSArray *sortArray = [[NSArray alloc]initWithArray:[newDict allKeys]];
NSMutableArray *newValues = [[NSMutableArray alloc]initWithArray:[sortArray sortedArrayUsingSelector:@selector(localizedStandardCompare:)]];
self.Numbers = newValues;
component1Row = 0;
[self.myPicker selectRow:0 inComponent:1 animated:NO];
[newDict release];
[sortArray release];
[newValues release];
}
if(component ==1)
{
component0Row = [pickerView selectedRowInComponent:0];
component1Row =row;
}
}
问题可能在
titleForRow
方法或numberOfRows
方法中。您必须确保没有超出所讨论数组的边界。@superllanboy nsarray有一个count方法,因此如果(indexIWant
很抱歉,我没有足够的经验来理解如何将这些语句合并到上述选择器设计的条件处理中