UIPickerView - 1st row selection does not call didSelectRow

前端 未结 5 978
我寻月下人不归
我寻月下人不归 2020-12-09 09:46

I have a UIPickerView on my UIView along with a UITextField. I am letting the user select a value from the picker or enter a custom va

5条回答
  •  既然无缘
    2020-12-09 10:07

    Instead of "pushing" the value of the picker each time you make a selection with this code:

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    

    you should "pull it" when the user clicks the button (or other event you are using) using something similar to:

    - (void)myAction:(id)sender
    {
    
        NSInteger row = [myPicker selectedRowInComponent:0];
        selectedText = [myArray objectAtIndex:(NSUInteger)row];
    
    
    }
    

    For clearing the text: The UITextField class provides a built-in button for clearing the current text. So if the user does not want that text he can discard it.

    myTextField.clearButtonMode = UITextFieldViewModeAlways; 
    

    So in the script, will you check if the TextField has a value, if it does have a value u use the TextField, if it doesn't have a value, you pull the information from the Picker.

提交回复
热议问题