简体   繁体   中英

Set range of a UIPickerView component

Is there a way to set the range of allowable selections in a UIPickerView?

I have a UIPickerView with 2 components each representing a musical note value. One is the lower note. One is the upper note. I want to ensure that the user doesn't make the upper note lower than the lower one and vice versa. Make sense? I'd prefer not to have to update the picker values each time either value changes. Any thoughts?

UIPickerView的屏幕截图

You could just check it in the didSelectRow method and revert if necessary. You'll need to store the row in a property.

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    //pseudocode
    if(RowIsIllegalTest)
    {
        //[pickerViewOne selectRow:pickerViewRow inComponent:(what component is it in?) animated:YES]
    }
    else
    {
        //update the row for next time around
        self.pickerViewRow = row;
    }
return;

}

edit: you'll also need to keep the stored pickerView rows seperate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM