Hi I am using picker view
, by default it is selecting the first row. I don't want this option. For example I am having "No" and "yes" options.If i give this option in pickerview "No " will be selected in pickerview (attached screenshot).I dont need this.I need first row as empty .once the user selects on "No" or "Yes" then only it need to show as a selected row. Related screenshot attached below.
How to this?
thanks in advance.
If you want to get this one by using UIPickerView
then pass the first component
of the picker view as a empty value,otherwise you can use custom pickerview
.
[pickerArray addObject:@""];//first element of the picker component.
You can't do deselecting all the rows in uipickerview.
One thing you can do is create an additional row(eg: Select Option) in the top and default selection change to that row. Dont forget to change in your delegate method.
In the viewDidLoad
add this line
[picker selectRow:**selectedRow** inComponent:0 animated:YES];
Note:selectedRow is the row number which you want to show as selected.
if you need to show selection indicator only on row selection from picker view
when dragging it on xib set its behavior in right pane uncheck the "shows selection indicator" and then in this method
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
PickerSamples.showsSelectionIndicator=YES;
}
here picker samples is my picker.....
This works for me
[picker selectRow:-1 inComponent:0 animated:NO];
来源:https://stackoverflow.com/questions/16976300/how-to-deleselect-a-row-from-uipickerview