diff --git a/cocos/ui/UIRadioButton.cpp b/cocos/ui/UIRadioButton.cpp index 11607e0e4b..bcd48fd7a3 100644 --- a/cocos/ui/UIRadioButton.cpp +++ b/cocos/ui/UIRadioButton.cpp @@ -194,7 +194,7 @@ void RadioButtonGroup::addRadioButton(RadioButton* radioButton) if(!_allowedNoSelection && _selectedRadioButton == nullptr) { - setSelectedButton(radioButton); + setSelectedButtonWithoutEventCallback(radioButton); } } } @@ -219,7 +219,7 @@ void RadioButtonGroup::removeRadioButton(RadioButton* radioButton) if(!_allowedNoSelection && _selectedRadioButton == nullptr && !_radioButtons.empty()) { - setSelectedButton(0); + setSelectedButtonWithoutEventCallback(0); } } } @@ -261,6 +261,12 @@ void RadioButtonGroup::setSelectedButton(int index) } void RadioButtonGroup::setSelectedButton(RadioButton* radioButton) +{ + setSelectedButtonWithoutEventCallback(radioButton); + onChangedRadioButtonSelect(_selectedRadioButton); +} + +void RadioButtonGroup::setSelectedButtonWithoutEventCallback(RadioButton* radioButton) { if(!_allowedNoSelection && radioButton == nullptr) { @@ -282,7 +288,6 @@ void RadioButtonGroup::setSelectedButton(RadioButton* radioButton) { _selectedRadioButton->setSelected(true); } - onChangedRadioButtonSelect(_selectedRadioButton); } std::string RadioButtonGroup::getDescription() const diff --git a/cocos/ui/UIRadioButton.h b/cocos/ui/UIRadioButton.h index 2e51820851..26d982451d 100644 --- a/cocos/ui/UIRadioButton.h +++ b/cocos/ui/UIRadioButton.h @@ -258,6 +258,7 @@ protected: void onChangedRadioButtonSelect(RadioButton* radioButton); void deselect(); + void setSelectedButtonWithoutEventCallback(RadioButton* radioButton); Vector _radioButtons; ccRadioButtonGroupCallback _radioButtonGroupEventCallback;