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.
- Use
-[<UIPickerViewDelegate> pickerView:viewForRow:forComponent:reusingView:]
to return a custom view for each row, such as aUILabel
. For the row you want to show up as disabled, you'll need to configure the view to reflect that disabledness. - 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
}
精彩评论