【问题标题】:Corona SDK onRowTouch gotoSceneCorona SDK onRowTouch gotoScene
【发布时间】:2014-09-05 15:17:02
【问题描述】:

我无法使用作曲家或故事板更改场景。当您在 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
        -- Called when the scene is still off screen and is about to move on screen
    elseif phase == "did" then
        -- Called when the scene is now on screen
        -- 
        -- INSERT code here to make the scene come alive
        -- e.g. start timers, begin animation, play audio, etc.
    end 
end

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

    if event.phase == "will" then
        -- Called when the scene is on screen and is about to move off screen
        --
        -- INSERT code here to pause the scene
        -- e.g. stop timers, stop animation, unload sounds, etc.)
    elseif phase == "did" then
        -- Called when the scene is now off screen
    end
end

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

    -- Called prior to the removal of scene's "view" (sceneGroup)
    -- 
    -- INSERT code here to cleanup the scene
    -- e.g. remove display objects, remove touch listeners, save state, etc.
end

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

-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

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

return scene

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    您的代码无法正常工作有几个原因。您在第 34 行有一个悬空的 end 并且您没有定义远足。您可能需要较小的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      • 1970-01-01
      • 2013-12-18
      • 2017-03-14
      • 2013-06-04
      • 1970-01-01
      相关资源
      最近更新 更多