How to deleselect a row from UIPickerview

纵然是瞬间 提交于 2019-12-02 12:17:50

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.....




回答5:


This works for me

[picker selectRow:-1 inComponent:0 animated:NO];


来源:https://stackoverflow.com/questions/16976300/how-to-deleselect-a-row-from-uipickerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!