1

注意:我正确设置了委托,并且 UIPicker 在 ios6 中完美运行。在 ios5 中,仅当我选择 row0 或 row5 时才调用 didSelectRow: 回调。我有 12 行。

有谁知道可能出了什么问题?

注意:UIPicker 的委托和数据源指向具有以下代码的类。

// returns the number of 'columns' to display.
        - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

            if ([pickerView isKindOfClass:[MIDatePicker class]]) {

                switch (self.pickermode) {
                    case MIDatePickerModeDayMonth:
                        return 2;
                        break;
                    case MIDatePickerModeDayMonthYear:
                        return 3;
                        break;

                    default:

                        break;
                }
            }

            return 3;
        }

        // returns the # of rows in each component..
        - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

            if ([pickerView isKindOfClass:[MIDatePicker class]]) {

                //month , day , year
                switch (component) {
                    case 0:{
                        return [self.monthsArray count];
                    }
                        break;
                    case 1:
                    {
                        return [self.daysArray count];
                    }

                    case 2:{
                        return [self.yearArray count];
                    }

                    default:
                        break;
                }
            }

            return 3;
        }

        // returns width of column and height of row for each component.
        - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{

            // month , day ,year
            switch (component) {
                case 0:{
                    return self.picker.frame.size.width/2;
                }

                case 1:
                    return self.picker.frame.size.width/6;

                case 2:{
                    return self.picker.frame.size.width/3;
                }

                default:
                    break;
            }
            return self.picker.frame.size.width;
        }
        - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{

            return pickerView.frame.size.height/5;
        }


        - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
            // month , day ,year
            switch (component) {
                case 0:{
                    return [NSString stringWithFormat:@" %@ ",[self.monthsArray objectAtIndex:row]];
                }
                case 1:
                    return [self.daysArray objectAtIndex:row];

                case 2:{
                    return [self.yearArray objectAtIndex:row];
                }

                default:
                    break;
            }
            return @"";

        }


    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
        NSLog(@"selected row:%d , component:%d" , row,component);
    }
4

1 回答 1

2

在 ios5 中:现在我通过将 float 转换为整数来获得对 didSelectRow 的所有调用。

我的观察:默认选择器高度是 216.0 。如果我将行高更改为pickerView.frame.size.height/3 or pickerView.frame.size.height/4 or even pickerView.frame.size.height/6;推理,则相同的代码可以工作:216.0 完全可以被 3、4、6 整除,当除以 5 时,它有 0.2 个分数。这就是我在pickerView.frame.size.height/5 的情况下只为row1 和row6 获得didSelect 调用的原因。

体面的修复可能是:

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{

    return (int) pickerView.frame.size.height/5;
}
于 2013-07-30T21:04:50.587 回答