I am getting strange behavior when I change a tableview size after creation. I create the TV with 10 rows, and a height of 200, which is enough to show 5 rows. This leads to this Before screenshot:
So far so good. After 5 seconds, I double the height of the TV, so all 10 rows will show. Instead, I get this After screenshot:
As you can see, it does not actually double in height, it only increases a bit. Furthermore, it actually moves downward on the screen, as if the y had changed. However, when I print() these values I get:
y:0 height: 200 contentHeight: 200 BEFORE
y:0 height: 400 contentHeight: 400 AFTER
So the y has not changed at all in the code. And the height has doubled, exactly like it should have. But that is not what shows on screen.
Can anyone explain this? Is changing a TV height not supported?
Here is the code I used to generate the screenshots.
[lua]local widget = require(‘widget’)
– Handle row rendering
local function onRowRender( event )
– Get reference to the row group
local row = event.row
– Cache the row “contentWidth” and “contentHeight” because the row bounds can change as children objects are added
local rowHeight = row.contentHeight
local rowWidth = row.contentWidth
local rowTitle = display.newText( row, "Row " … row.index, 0, 0, nil, 14 )
rowTitle:setFillColor( { 1, 0, 0 } )
– Align the label left and vertically centered
rowTitle.anchorX = 0
rowTitle.x = 0
rowTitle.y = rowHeight * 0.5
end
– Create the tableView
local tableView = widget.newTableView
{
x = display.contentWidth/2,
y = 0,
height = 200,
width = 320,
onRowRender = onRowRender
}
tableView.anchorY = 0
print(tableView.y, tableView.height, tableView.contentHeight)
– Insert rows
for i = 1, 10 do
tableView:insertRow{}
end
local function resizeTV()
tableView.height = 2*tableView.height
print(tableView.y, tableView.height, tableView.contentHeight)
end
– 5 seconds after creation, increase the table view height
timer.performWithDelay(5000, resizeTV)[/lua]