开发者

Can I disable selection in specific UIPickerView item?

开发者 https://www.devze.com 2023-04-07 22:57 出处:网络
I can find a post that teach to use delegate 开发者_JAVA百科method to check if the row valid and then scroll to the right one if not.

I can find a post that teach to use delegate 开发者_JAVA百科method to check if the row valid and then scroll to the right one if not.

But that's not I want. Can I disable the specific row after the pickerView initialized? Like "Gray-out" the row and can't stop indicator on it.

Thank you, experts.


There are two parts to doing this.

  1. Use -[<UIPickerViewDelegate> pickerView:viewForRow:forComponent:reusingView:] to return a custom view for each row, such as a UILabel. For the row you want to show up as disabled, you'll need to configure the view to reflect that disabledness.
  2. In -[<UIPickerViewDelegate> pickerView:didSelectRow:inComponent:], you'll need to detect when the disabled is selected, and then use -[UIPickerView selectRow:inComponent:animated:] to "rollback" to a "valid" row.


You could also just leave a blank in the implementation, e.g.:

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if(row==0){
//Code
}
if(row==1){

//BLANK

}
if(row==2){
//Code
}
0

精彩评论

暂无评论...
验证码 换一张
取 消