Can Segmented Controll Be Set Default After Construct.

I want to set default value to segmented control after construct.

But segmentedControl.defaultSegment do not worked.

local segmentedControl = widget.newSegmentedControl { left = 50, top = 150, segments = { "Hello", "Corona", "SDK!" }, defaultSegment = 1, onPress = onPress, } segmentedControl.defaultSegment = 2 --- \<\<\< NOT WORK

I read docs, but I can not find how to do.

Is there API ?

Hi @syun,

At this time, there’s not a post-creation set method for the segmented control. However, if you’re creating the segmented control in a Storyboard scene and not clearing out that scene entirely (i.e, if you want to quickly go back to it), then the segmented control should remain set to what you had it. But, if you’re creating a new scene and want a new segmented control set to some default, how about just passing a variable to the scene and use that value to set “defaultSegment” during creation of the segmented control?

Best regards,

Brent

Hi Brent,

Thank you for reply.

I see there is not method to set value now. I will change code to create new segmented control with defaultValue at scene:enterScene().

Hi @syun,

At this time, there’s not a post-creation set method for the segmented control. However, if you’re creating the segmented control in a Storyboard scene and not clearing out that scene entirely (i.e, if you want to quickly go back to it), then the segmented control should remain set to what you had it. But, if you’re creating a new scene and want a new segmented control set to some default, how about just passing a variable to the scene and use that value to set “defaultSegment” during creation of the segmented control?

Best regards,

Brent

Hi Brent,

Thank you for reply.

I see there is not method to set value now. I will change code to create new segmented control with defaultValue at scene:enterScene().