hello good morning, we have acquired the pro license and we are using build 1093.
Following the example of pjavelasco, i have proven to work correctly the “deleteRow” function. But when I delete a row, and after try to add a new row I get an error.
I have taken the example of “pjavelasco” and I inserted a button to add rows:
[lua]-- Import the widget library
local widget = require( “widget” )
local list
local addButton
local listRows = {} – my new table
– Handle row rendering
local function onRowRender( event )
local row = event.row
local rowTitle = display.newText( row, "List item " … row.index, 0, 0, native.systemFontBold, 16 )
rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )
rowTitle.y = row.contentHeight * 0.5
rowTitle:setTextColor( 0, 0, 0 )
table.insert(listRows, row.index) – Add the row.index to my table
end
– Handle row touch events
local function onRowTouch( event )
local phase = event.phase
local row = event.row
local found
if “release” == phase then
found = table.indexOf(listRows, row.index)
table.remove(listRows, found) – Delete the row from my table
list:deleteRow(row.index)
end
end
– Create a tableView
list = widget.newTableView
{
top = 38,
width = 320,
height = 448,
maskFile = “mask-320x448.png”,
onRowRender = onRowRender,
onRowTouch = onRowTouch,
}
– insert rows into list (tableView widget)
for i = 1, 3 do
list:insertRow{
height = 72,
}
end
local function addRow(event)
if event.phase == “ended” then
list:insertRow{
height = 72,
}
end
end
– Create a button for insert new rows
addButton = widget.newButton{
left = 25,
top = 5,
width = 100,
height = 30,
label = “Add”,
onEvent = addRow,
}
[/lua]
In the code above, my modus operandi is as follows:
-
I eliminate the third row by touch on herself
-
Pulse the “add” button to insert a new row and I get the following error:
?:0: attempt to perform arithmetic on field ‘contentHeight’ (a nil value)
stack traceback:
[C]: ?
?:in function <?:812>
(tail call): ?
c:…\main.lua: 54 in function '_onEvent’
…
I hope your help
thanks in advance