Tab bar errors

I have tried to create a project with a tab bar with 4 buttons. I used the graphics from the sample code.

[lua]-----------------------------------------------------------------------------------------

– main.lua


local widget = require (“widget”)

local tabButtons =
{
{
id = “Contact”,
label = “Event Contact”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
onPress = function() print( “Tab 1 pressed” ) end,
selected = true,
defaultFile = “assets/tabIcon.png”,
overFile = “assets/tabIcon-down.png”
},
{
id = “Info”,
label = “Event Info”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
onPress = function() print( “Tab 2 pressed” ) end,
selected = false,
defaultFile = “assets/tabIcon.png”,
overFile = “assets/tabIcon-down.png”
},
{
id = “Resources”,
label = “Resources Used”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
onPress = function() print( “Tab 3 pressed” ) end,
selected = false,
defaultFile = “assets/tabIcon.png”,
overFile = “assets/tabIcon-down.png”
},
{
id = “Additional”,
label = “Additional Info”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
onPress = function() print( “Tab 4 pressed” ) end,
selected = false,
defaultFile = “assets/tabIcon.png”,
overFile = “assets/tabIcon-down.png”
},
}

local tabBar = widget.newTabBar
{
top = display.contentHeight - 50,
width = display.contentWidth,
backgroundFile = “assets/tabbar.png”,
tabSelectedLeftFile = “assets/tabBar_tabSelectedLeft.png”,
tabSelectedMiddleFile = “assets/tabBar_tabSelectedMiddle.png”,
tabSelectedRightFile = “assets/tabBar_tabSelectedRight.png”,
tabSelectedFrameWidth = 20,
tabSelectedFrameHeight = 52,
buttons = tabButtons
}[/lua]

When I run this in the simulator, I get the following error:

ERROR: widget.newTabBar: width expected, got nil

stack traceback:

    [C]: ?

    [C]: in function ‘error’

    ?: in function ‘?’

    ?: in function <?:606>

    (tail call): ?

    …ers/seandzafovic/Desktop/Outreach Report V2/main.lua:50: in main chunk

Why is width nil? Am I not setting it with width = display.contentWidth?

Hi @sdzafovic,

It appears that you’re missing the width and height settings in the actual tab definitions above where you declare the widget (the width/height of your defaultFile/overFile for each tab). See the example code in this document:

http://docs.coronalabs.com/api/library/widget/newTabBar.html

Please report back if this doesn’t solve the issue, and I’ll investigate further.

Best regards,

Brent Sorrentino

That seems to have worked. I must have missed that when copy/pasting the example code.

Hi @sdzafovic,

It appears that you’re missing the width and height settings in the actual tab definitions above where you declare the widget (the width/height of your defaultFile/overFile for each tab). See the example code in this document:

http://docs.coronalabs.com/api/library/widget/newTabBar.html

Please report back if this doesn’t solve the issue, and I’ll investigate further.

Best regards,

Brent Sorrentino

That seems to have worked. I must have missed that when copy/pasting the example code.