如何使用标签栏访问lua文件?

时间:2014-04-18 20:46:30

标签: lua corona tabbar

尝试访问其中构建了标签栏的文件时出错。有谁知道我做错了什么。 Corona SDK告诉我我的错误是在代码部分,我实际创建标签栏,而不是按钮。感谢

以下是我在其中创建标签栏的MainPage.lua场景的代码。

local tabBar = nil
function scene: create (event)
local group = scene.view
local tabButtons = 
{
    {
        width = 20, 
        height = 32,
        defaultFile = "assets/home.png",
        overFile = "assets/PressHome.png",
        label = "Home",
        font = tabLabelFont,
        size = tabLabelFontSize,
        onPress = function() composer.gotoScene( "Home" ); end,
    },
    {
        width = 20, 
        height = 32,
        defaultFile = "assets/Explore.png",
        overFile = "assets/Explore.png",
        label = "Explore",
        font = tabLabelFont,
        size = tabLabelFontSize,
        onPress = function() composer.gotoScene( "Explore" ); end,
    },
    {
        width = 20, 
        height = 32,
        defaultFile = "assets/Post.png",
        overFile = "assets/Post.png",
        label = "Post",
        font = tabLabelFont,
        size = tabLabelFontSize,
        onPress = function() composer.gotoScene( "Post" ); end,
    },
    {
        width = 20, 
        height = 32,
        defaultFile = "assets/Notification.png",
        overFile = "assets/Notification.png",
        label = "Notification",
        font = tabLabelFont,
        size = tabLabelFontSize,
        onPress = function() composer.gotoScene( "Notification" ); end,
    },
    {
        width = 20, 
        height = 32,
        defaultFile = "assets/Profile.png",
        overFile = "assets/Profile.png",
        label = "Profile",
        font = tabLabelFont,
        size = tabLabelFontSize,
        onPress = function() composer.gotoScene( "Profile" ); end,
    }
}

-- Create a tab-bar and place it at the bottom of the screen
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
}
group: insert(tabBar)
composer.gotoScene("Home")  
end
scene:addEventListener( "create", scene )
return scene

这是登录页面中应该访问标签栏页面的方法。

local function EnterPage( event )
    composer.gotoScene("MainPage")
end

这就是错误所说的

stack traceback:
    ?: in function '?'
    ?: in function <?:703>
    (tail call): ?
    ?: in function <?:122>
    (tail call): ?
    MainPage.lua:127: in main chunk
    [C]: in function 'require'
    ?: in function <?:797>
    (tail call): ?
    LogIn.lua:78: in function <LogIn.lua:70>
    ?: in function <?:218>

主页面的第127行是表示“tabBar = widget.newTabBar”的行 登录页面中的错误只是转到gotoScene(MainPage)方法

1 个答案:

答案 0 :(得分:0)

“文件:?尝试索引零值”非常有用:它表示您正在执行a.b形式的操作,例如a.b = somethinga.b() {{1}没有。鉴于它发生的线,这肯定是因为你忘了

a

靠近文件顶部。

如果该行已经存在(widget = require 'widget' 中),请检查MainPage.lua是否已被覆盖:

widget

如果它不是零,那么你在发布的信息中出错了(错误的行号等)或者你尝试了很多东西而且信息混淆了。你可以尝试,只是为了确定,

print('widget is', widget)
tabBar = widget.newTabBar
...

如果可行,那么您知道在widget = require 'widget' tabBar = widget.newTabBar 中的某个地方覆盖widget,代码未显示。你也应该试试

MainPage.lua

如果可行,但newTabBar仍然不起作用,请尝试用corona newTabBar网站上的示例替换您的选项。