widget.newSwitch()

local widget = require( “widget” )

– Handle press events for the checkbox
local function onSwitchPress( event )
local switch = event.target
print( “Switch with ID '”…switch.id…"’ is on: "…tostring(switch.isOn) )
end

– Create the widget
local onOffSwitch = widget.newSwitch
{
left = 250,
top = 200,
style = “onOff”,
id = “onOffSwitch”,
onPress = onSwitchPress
}

so i put this in “option.lua” . i turn the switch to “ON”

i move to “menu.lua” and use 'storyboard.removeScene(“option”) to clear the previous scene

when i go back to “option.lua”, it goes back to “OFF” state (that’s because of removeScene()) … what do i do to keep it in it’s “ON” state( i turned it ON the last time) ?

You have to save your state somewhere in your code, then when you recreate the scene set the switch to the saved state:

onOffSwitch:setState( { isOn=true } )

See a small demo I posted on the following thread : http://forums.coronalabs.com/topic/42610-new-quest-splitview-programmatically-updating-widgets-demo/?hl=splitview

This demo illustrates how you can programmatically update the widgets. Hope this helps.

@primoz.cerar :

 thnx, great idea…save/load the button’s state…got it working last night,  with a few bugs…

@ksan:
  nothing beats a tutorial with a demo. you’re the best ksan.will definitely be absorbing ur tutz :))  thnx!
 

gracias amigos! :smiley:
 

Hi - after updating to an iOS7 compatible build (1262) my switch widgets aren’t responding to setState commands - the slider sits in the middle of the switch (i.e. not on or off).

Here’s the code I’m using to update: objMainMenu.MenuMessageDialog.onOffSwitchDrive:setState( { isOn = true } )

Any ideas how to fix this?

  freakyswitch.png

Got for 2150+ build. The switch bugs were fixed very recently. Hope this helps.

Ahhh crap - I’m not Graphics 2.0 compliant yet, and compatibility mode doesn’t help, so I’m stuck on pre-2000 for now…

You have to save your state somewhere in your code, then when you recreate the scene set the switch to the saved state:

onOffSwitch:setState( { isOn=true } )

See a small demo I posted on the following thread : http://forums.coronalabs.com/topic/42610-new-quest-splitview-programmatically-updating-widgets-demo/?hl=splitview

This demo illustrates how you can programmatically update the widgets. Hope this helps.

@primoz.cerar :

 thnx, great idea…save/load the button’s state…got it working last night,  with a few bugs…

@ksan:
  nothing beats a tutorial with a demo. you’re the best ksan.will definitely be absorbing ur tutz :))  thnx!
 

gracias amigos! :smiley:
 

Hi - after updating to an iOS7 compatible build (1262) my switch widgets aren’t responding to setState commands - the slider sits in the middle of the switch (i.e. not on or off).

Here’s the code I’m using to update: objMainMenu.MenuMessageDialog.onOffSwitchDrive:setState( { isOn = true } )

Any ideas how to fix this?

  freakyswitch.png

Got for 2150+ build. The switch bugs were fixed very recently. Hope this helps.

Ahhh crap - I’m not Graphics 2.0 compliant yet, and compatibility mode doesn’t help, so I’m stuck on pre-2000 for now…