2013-10-13 5 views
1

나는 1 열 테이블을 생성하는 TableView 위젯을 사용하고 있습니다. 내 onRowRender() 함수는 예제와 동일하지만 앱을 실행하면 모든 행의 텍스트가 동일한 지점에 걸려 테이블과 함께 이동하지 않습니다. rowTitle.y 속성의 값을 row.y으로 변경해도 텍스트를 올바른 시작 위치에 놓을지라도 테이블을 스크롤 할 때 텍스트가 움직이지 않습니다. 여기 TableView 위젯의 텍스트가 스크롤되지 않음

코로나의 설명서에서 오는 내 교과서도 내가에서 일하고 있어요 예제 코드입니다 :

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 

뭔가가 있나요 : 여기

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) 

그리고 나의 코드 나는 그리워 해? 테이블 행을 스크롤 할 수있는 동안 텍스트가 그대로있는 이유는 무엇입니까?

답변

2

개체를 행 그룹에 삽입해야합니다.

row:insert(rowTitle) 
관련 문제