Corona SDK 的 onRowTouch 函数用于设置行触摸事件,gotoScene 操作用于跳转到另一个场景。

我无法使用composer或storyboard改变场景。我尝试在点击tableview中的一行时更改场景。我能够从主文件更改场景到带有tableview的文件。但是,tableview的触摸功能不起作用。

以下是我的一些代码:

    local widget = require( "widget" )
    local storyboard = require( "storyboard" )
    local composer = require( "composer" )
    local scene = composer.newScene()

function RowTouch( event )
    composer.gotoScene( "thehike" )
end

myTable = widget.newTableView
    {
        width = display.contentWidth,
        height = display.contentHeight,
        backgroundColor = { .47, .66, .53 },
        topPadding = 0,
        hideBackground = false,
        onRowRender = onRowRender,
        onRowTouch = RowTouch,
        noLines = true,
    }

    for i=1, #hike do
        myTable:insertRow{
        rowHeight = 220,
        isCategory = false,
        lineColor = { .47, .66, .53 }
        }
    end
end

function scene:show( event )
    local sceneGroup = self.view
    local phase = event.phase

    if phase == "will" then
        -- 当场景仍在离屏幕的状态并准备移动到屏幕上时调用
    elseif phase == "did" then
        -- 当场景现在在屏幕上时调用
        --
        -- 插入代码来使场景活起来
        -- 例如启动计时器,开始动画,播放音频等
    end
end

function scene:hide( event )
    local sceneGroup = self.view
    local phase = event.phase

    if event.phase == "will" then
        -- 当场景在屏幕上并准备移动到屏幕外时调用
        --
        -- 插入代码来暂停场景
        -- 例如停止计时器,停止动画,卸载声音等
    elseif phase == "did" then
        -- 当场景现在离开屏幕时调用
    end
end

function scene:destroy( event )
    local sceneGroup = self.view

    -- 在移除场景"view"之前调用(sceneGroup)
    --
    -- 插入代码来清理场景
    -- 例如移除显示对象,移除触摸侦听器,保存状态等
end

---------------------------------------------------------------------------------

-- 监听器设置
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

-----------------------------------------------------------------------------------------

return scene
点赞
用户1997085
用户1997085

你的代码有几个问题。你在第34行有一个悬空的 end,而且你没有定义 hike。为了显示视图中的行,你可能需要一个较小的 rowHeight

 local myTable = widget.newTableView
    {
        left = 0,
        top = 0,
        height = 330,
        width = 300
    }

 myTable:insertRow(
        {
            isCategory = false,
            rowHeight = 40,
            rowColor = rowColor,
            lineColor = {.47, .66, .53}
        }
    )

此外,该文档上有足够的信息[1]。

[1] http://docs.coronalabs.com/api/library/widget/newTableView.html

2014-09-05 07:17:02