Does UIPickerView's selectRow:inComponent:animated: call pickerView:didSelectRow:inComponent:?

前端 未结 3 862
南笙
南笙 2021-01-04 05:19

Does UIPickerView\'s selectRow:inComponent:animated: call pickerView:didSelectRow:inComponent:? Otherwise, can I just call it myself?

Thank

相关标签:
3条回答
  • 2021-01-04 05:55

    It does not, although it is possible to call it manually.

    0 讨论(0)
  • 2021-01-04 05:59

    You do have to call it manually and you do it though the delegate.

    // In this example the UIPickerView object is in a property
    ...
    self.pickerView.datasource = self;
    self.pickerView.delegate = self;
    
    // Selects the row in the specified component
    [self.pickerView selectRow:0 inComponent:0 animated:NO];
    
    // Manually calls pickerView:didSelectRow:inComponent:
    [self pickerView:self.pickerView didSelectRow:0 inComponent:0];
    
    0 讨论(0)
  • 2021-01-04 06:14

    It does not call delegate method with swift too, but you can do it manually also. Decision for swift 3 and swift 4:

    self.pickerView.datasource = self
    self.pickerView.delegate = self
    
    self.pickerView.selectRow(0, inComponent: 0, animated: false)
    self.pickerView.delegate?.pickerView?(self.pickerView, didSelectRow: 0, inComponent: 0)
    
    0 讨论(0)
提交回复
热议问题