在表格行中添加文本框-Corona SDK

在我的 Corona 项目中,我想在表格行中显示文本字段。以下是代码,它只显示一个文本字段,我想在可用的数据行中显示文本字段。

local function onRowRender( event )
    local phase = event.phase
    local row = event.row

    local itemObj = GetItemDetails(row.index);

    local txt = itemObj.itemName;
    if(#txt > 25) then
        txt = string.sub(txt,1,25);
        txt = txt.."..";
    end

    local rowTitle = display.newText( row, "\t"..txt, 0, 0, "impact", 14 )
    if(deviceName == "iPhone" or deviceName == "iPad") then
        rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )
    else
        rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )+15
    end
    rowTitle.y = row.contentHeight * 0.5
    rowTitle:setTextColor(98, 71, 24)

    local rowqtytxt=nil;
    if(deviceName == "iPhone" or deviceName == "iPad") then
        rowqtytxt= native.newTextField( 0, 0,32, 32 ,onSubmitted);
        rowqtytxt.x = 125;
        rowqtytxt.hasBackground = false;
        --rowqtytxt:addEventListener( "userInput", textListener )
        rowqtytxt.size = 32;
    else
        rowqtytxt = native.newTextField( 0, 0,32, 32 ,onSubmitted);
        rowqtytxt.x = 207;
        rowqtytxt.hasBackground = false;
       -- rowqtytxt:addEventListener( "userInput", textListener )
        rowqtytxt.size = 32;
    end

    rowqtytxt.y = row.contentHeight * 0.5
    rowqtytxt:setTextColor(98, 71, 24)
    return true;
end

以上代码仅显示一个文本字段。请帮助解决这个问题。

点赞
用户1609914
用户1609914

当你说“数据可用行”时,你是什么意思?在我看来,你的意思是itemObj不总是有数据吗?

如果是这种情况,那么你需要在一个_if_块中包装添加文本字段:

if(itemObj ~= nil) then
    --Adding textField code
end

此外,此函数似乎呈现单个行。因此,您需要将其包装在for循环中。类似于

local i;
-- #表示“长度”
for i=1, #yourDataSource do
    onRowRender(yourItemData)
end
2014-01-31 09:49:46
用户1870706
用户1870706

在 Corona SDK 中,widget.newTableView 是基于显示组的。你不能将 native.* 对象插入到显示组中。因此,tableView 不能将文本字段作为行的一部分滚动。

几周前,我们发布了一个教程,演示如何将 native.newTextField 绑定到显示组中。http://coronalabs.com/blog/2013/12/03/tutorial-customizing-text-input/

社区项目正在构建该教程中所提到的想法的一种变体,您可以在论坛上找到它。

这个想法是使用 enterFrame 监听器将 native.newTextField 移动到与其绑定的显示对象的位置。然而,这种方法对于 tableView 不实用的原因在于,当 tableView 将行滚动到屏幕外时,它们可能无法正确地被移除。

2014-02-02 03:48:38