Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Uipicker在同时旋转两个部件时崩溃_Iphone_Uipicker - Fatal编程技术网

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很抱歉,我没有足够的经验来理解如何将这些语句合并到上述选择器设计的条件处理中