UIPickerView first select value problem

I have successfully implemented UIPickerView. However, I have a problem when choosing values.

According to the standard way, I implemented a method

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 
 // method implementation...
}

The problem is that I am trying to select the very first value. By default, the first element is selected, so if I want the method to be called for the first line, I need to scroll down, select a value, then scroll to the first again. What am I missing here? Is there any other way to do this? Also, is it possible to get the selected value without moving the collector? Since I have a view containing components like UITextField and UIPickerView, and I need to scan the whole view to get the values ​​of the components.

thanks Leonardo

+3
source share
1 answer

You can use the selectedRowInComponent: method to get a selection without waiting for the action to be used.

Or if you want to perform a user action, you can add a space (or use-current, or no-selection, etc.) somewhere and use the selectRow: inComponent: animated: method to select it.

+3
source

Source: https://habr.com/ru/post/1762923/


All Articles