How to deleselect a row from UIPickerview

£可爱£侵袭症+ 提交于 2019-12-02 03:58:49

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.

Mudit Bajpai

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