UIPickerView - 1st row selection does not call didSelectRow

前端 未结 5 967
我寻月下人不归
我寻月下人不归 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:08

    -(void)textFieldDidBeginEditing:(UITextField *)textField
    {
        // Only for the text field with the picker
        if (textField == self.yourTextField && [textField length]!=0)
        {
            // Select the first row programmatically 
            [self.categoriesPicker selectRow:0 inComponent:0 animated:YES];
            // The delegate method isn't called if the row is selected programmatically
            [self pickerView:self.categoriesPicker didSelectRow:0 inComponent:0];
        }
    
    
    
    }
    
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        //Do all the stuff to populate the TextField
    }
    

提交回复
热议问题