composer.gotoScene and tabbar non sync'ing

Hello! I have a tabbar in main.lua like this:

-- EVENTI BOTTONI TABBAR: local function onGenerateView(event) composer.gotoScene("scenes.generate", {effect = "slideRight"}) end local function onInfoView(event) composer.gotoScene("scenes.info", {effect = "fromBottom"}) end local function onOptionsView(event) composer.gotoScene("scenes.options", {effect = "slideLeft"}) end -- BOTTONI TABBAR: local tabButtons = { { label = "", defaultFile = "img/buttons/home.png", overFile = "img/buttons/home.png", width = 28, height = 28, onPress = onGenerateView, selected = true}, { label = "", defaultFile = "img/buttons/info.png", overFile = "img/buttons/info.png", width = 28, height = 28, onPress = onInfoView}, { label = "", defaultFile = "img/buttons/options.png", overFile = "img/buttons/options.png", width = 41.6, height = 28, onPress = onOptionsView}, } -- TABBAR: local tabBar = widget.newTabBar{ top = display.contentHeight - 42, -- 50 is default height for tabBar widget buttons = tabButtons }

And a function in optionsList.lua (a scene which is NOT connected to any tabbar button and is called by a composer.gotoScene function in options.lua) triggered on onPress button like this:
 

local function backToGenerate() composer.gotoScene("scenes.generate", {effect = "slideRight"}) end

Now, when the function is called onPress, it properly gets me to generate.lua scene. But then the Options tabbar button won’t work, unless I press the Generate tabbar button (i.e. the scene where I already am, since the function sent me there). It looks like the tabbar is not updated/refreshed. Composer “thinks” I’m still in optionsList scene, until I manually press the tabbar button of the scene where I already am (Generate).
 
I hope I have explained myself and that someone can help. Thank you in advance!
 
Pietro

If I followed this right, you need to programmatically set the tabBar to the button for the scene you’re in.  Look at:

http://docs.coronalabs.com/api/type/TabBarWidget/setSelected.html

And put it in your scene’s show() event to make sure it’s tab is selected.

Rob

Dear Rob, thank you! You followed right and gave the right solution. I directly used tabBar:setSelected( 1, true ) instead of composer.gotoScene in my programmatic call, after declaring tabBar as global in main.lua (globals.tabBar, like in https://coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/)..)

It does work, I hope it’s not bad practice.

Pietro

Not a bad practice at all.  Many apps have ways of activating screens without using the tabBar but the tabBar needs to be updated.

Good luck

Rob

If I followed this right, you need to programmatically set the tabBar to the button for the scene you’re in.  Look at:

http://docs.coronalabs.com/api/type/TabBarWidget/setSelected.html

And put it in your scene’s show() event to make sure it’s tab is selected.

Rob

Dear Rob, thank you! You followed right and gave the right solution. I directly used tabBar:setSelected( 1, true ) instead of composer.gotoScene in my programmatic call, after declaring tabBar as global in main.lua (globals.tabBar, like in https://coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/)..)

It does work, I hope it’s not bad practice.

Pietro

Not a bad practice at all.  Many apps have ways of activating screens without using the tabBar but the tabBar needs to be updated.

Good luck

Rob