1

TableView1列のテーブルを作成するウィジェットを使用しています。私のonRowRender()関数は例と同じですが、アプリを実行すると、すべての行のテキストが同じ場所に留まり、テーブルと一緒に移動しません。rowTitle.yプロパティの値をに変更するとrow.y、テキストが正しい開始位置に配置されますが、テーブルをスクロールしても移動しません。

これは私が取り組んでいるサンプルコードです。これはコロナのドキュメントから来ており、私の教科書にもあります。

local widget = require( "widget" )

-- Listen for tableView events
local function tableViewListener( event )
    local phase = event.phase

    print( event.phase )
end

-- Handle row rendering
local function onRowRender( event )
    local phase = event.phase
    local row = event.row

    local rowTitle = display.newText( row, "Row " .. row.index, 0, 0, nil, 14 )
    rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )
    rowTitle.y = row.contentHeight * 0.5
    rowTitle:setTextColor( 0, 0, 0 )
end

-- Handle row's becoming visible on screen
local function onRowUpdate( event )
    local row = event.row

    print( "Row:", row.index, " is now visible" )
end

-- Handle touches on the row
local function onRowTouch( event )
    local phase = event.phase

    if "press" == phase then
        print( "Touched row:", event.target.index )
    end
end

-- Create a tableView
local tableView = widget.newTableView
{
    top = 100,
    width = 320, 
    height = 510,
    maskFile = "mask-410.png",
    listener = tableViewListener,
    onRowRender = onRowRender,
    onRowTouch = onRowTouch,
}


-- Create 100 rows
for i = 1, 100 do
    local isCategory = false
    local rowHeight = 40
    local rowColor = 
    { 
        default = { 255, 255, 255 },
    }
    local lineColor = { 220, 220, 220 }

    -- Make some rows categories
    if i == 25 or i == 50 or i == 75 then
        isCategory = true
        rowHeight = 24
        rowColor = 
        { 
            default = { 150, 160, 180, 200 },
        }
    end

    -- Insert the row into the tableView
    tableView:insertRow
    {
        isCategory = isCategory,
        rowHeight = rowHeight,
        rowColor = rowColor,
        lineColor = lineColor,
    }
end 

-- delete the tenth row in the tableView
tableView:deleteRow( 10 )   

そして、ここに私のコードがあります:

local widget = require "widget"
display.setStatusBar(display.HiddenStatusBar)
local availableSections = {"Intro", "Verse", "Chorus", "Verse", "Chorus", "Interlude", "Breakdown", "Verse", "Chorus", "Outro"}

--listen for tableView press events
local function tableViewListener( event )
    local phase = event.phase
    local row = event.target
    print(event.phase)
end

--render rows
local function onRowRender( event )
    local phase = event.phase
    local row = event.row

    local rowTitle = display.newText(availableSections[row.index], 0, 0, system.nativeFont, 24)
    rowTitle.x = row.x - (row.contentWidth * 0.5) + (rowTitle.contentWidth * 0.5) + 30
    rowTitle.y = row.contentHeight * 0.5
    rowTitle:setTextColor(1, 1, 1)
end

--handle row touches
local function onRowTouch( event )
    local phase = event.phase
    local row = event.target

    print("Row " .. row.index .. " touched.")

    if phase == "press" then
        print("Touched row:", event.target.index)
    end
end

-- Create a tableView
local list = widget.newTableView
{
    width = display.contentWidth, 
    height = display.contentHeight,
    --maskFile = "mask-410.png",
    listener = tableViewListener,
    onRowRender = onRowRender,
    onRowTouch = onRowTouch,
}

-- Create rows
for i = 1, table.getn(availableSections) do
    local isCategory = false
    local rowHeight = display.contentHeight/table.getn(availableSections)
    local rowColor = 
    { 
        default = { 255, 255, 255 },
    }
    local lineColor = { 220, 220, 220 }

    -- Insert the row into the tableView
    list:insertRow
    {
        isCategory = isCategory,
        rowHeight = rowHeight,
        rowColor = rowColor,
        lineColor = lineColor,
    }
end  

足りないものはありますか?表の行がスクロール可能であるのに、テキストがそのままの場所に残るのはなぜですか?

4

1 に答える 1