Hi,
I’m using a segment control and want to be able to set it to particular value when I show it (not always the default). Is there a way to set it?
Thanks,
Nathan.
Hi,
I’m using a segment control and want to be able to set it to particular value when I show it (not always the default). Is there a way to set it?
Thanks,
Nathan.
Hi Nathan,
When you declare the SegmentedControl, you can set the segment with the “defaultSegment” parameter, as follows:
[lua]
local segmentedControl = widget.newSegmentedControl
{
left = 50,
top = 150,
segments = { “Hello”, “Corona”, “SDK!” },
defaultSegment = 3,
onPress = onPress,
}
[/lua]
Does that help?
Brent
I’m declaring the default OK, but after it’s declared, when the user starts a new “level” in my game I want to reset it to the default again (they may have changed it during the last level).
Looking for something like segmentedControl:setSegment(3).
Nathan.
Hi Nathan,
So are you keeping the scene (with the SegmentedControl) in memory, i.e. if it’s part of a Storyboard scene, do you keep that scene around in the background? If so, there’s not currently a post-declaration method to set a segment… it’s been discussed, but not too many people have requested it. Anyway, if you keep the scene in the view, I’m afraid you’ll have to re-create the widget when you return to it. But if you’re already clearing the scene, you’ll need to recreate the widget anyway, and then you can just set the segment based on your internal data, reading from a text file, or whatever you need.
Hope this helps somewhat,
Brent
Brent,
Yes, I’m keeping it in memory - just hiding it. OK, I’ll have to dump the widget and hand-roll it.
Thanks anyway.
Nathan.
Hi Nathan,
When you declare the SegmentedControl, you can set the segment with the “defaultSegment” parameter, as follows:
[lua]
local segmentedControl = widget.newSegmentedControl
{
left = 50,
top = 150,
segments = { “Hello”, “Corona”, “SDK!” },
defaultSegment = 3,
onPress = onPress,
}
[/lua]
Does that help?
Brent
I’m declaring the default OK, but after it’s declared, when the user starts a new “level” in my game I want to reset it to the default again (they may have changed it during the last level).
Looking for something like segmentedControl:setSegment(3).
Nathan.
Hi Nathan,
So are you keeping the scene (with the SegmentedControl) in memory, i.e. if it’s part of a Storyboard scene, do you keep that scene around in the background? If so, there’s not currently a post-declaration method to set a segment… it’s been discussed, but not too many people have requested it. Anyway, if you keep the scene in the view, I’m afraid you’ll have to re-create the widget when you return to it. But if you’re already clearing the scene, you’ll need to recreate the widget anyway, and then you can just set the segment based on your internal data, reading from a text file, or whatever you need.
Hope this helps somewhat,
Brent
Brent,
Yes, I’m keeping it in memory - just hiding it. OK, I’ll have to dump the widget and hand-roll it.
Thanks anyway.
Nathan.