Problem with TableView and updating its content

Hi

I’m filling up the content of a tableView from SQLite using a simple query:

for row in db:nrows("SELECT \* FROM main WHERE difficulty=" .. param .. " ORDER BY status, topHeight DESC") do

Then I put these values inside a function, to calculate the values

 local function onRowRender( event ) local phase = event.phase local row = event.row local function subs(time, height, status, routeh) local t if ( dbRec[row.index].status == 1 ) then t = "top time: "..timeConversion(time) else t = "climbed: "..percentage( height, status, routeh ).."%" end return t end

and enter them inside a table row

 local value = {} value[row.index] = subs(dbRec[idx].timeBest, dbRec[idx].topHeight, dbRec[idx].status, dbRec[idx].routeH ) local subTitle2 = display.newText( row, value[row.index], 0, 0, nil, 18 ) subTitle2:setReferencePoint( display.CenterRightReferencePoint ) subTitle2.x = row.contentWidth - 20 subTitle2.y = row.contentHeight - 24 subTitle2:setTextColor( 90, 90, 90 )

All this works just great for all the table rows, which are on screen. But as soon as I scroll down, these values are overriden by some other.

Can someone please help?

I would guess it’s an issue with the relation between row.index used in most cases, and [idx], which it is not clear at all how gets incremented.

Basically, it’s impossible to tell from this code if your indice “idx”, which must be just right every time through this code, whether it is set properly each time. Perhaps adding a print(" – row.index, idx == ", row.index, idx) would be helpful?

Yes. There is something wrong. As soon as I start scrolling idx doesn’t change anymore.

 – row.index, idx ==   1       1

 – row.index, idx ==   2       2

 – row.index, idx ==   3       3

 – row.index, idx ==   4       4

 – row.index, idx ==   5       5

 – row.index, idx ==   6       6

 – row.index, idx ==   7       7

 – row.index, idx ==   8       8

 – row.index, idx ==   9       9

 – row.index, idx ==   10      10

 – row.index, idx ==   11      11

 – row.index, idx ==   12      12

 – row.index, idx ==   13      13

 – row.index, idx ==   14      14

 – row.index, idx ==   15      16

 – row.index, idx ==   16      16

 – row.index, idx ==   3       16

 – row.index, idx ==   2       16

 – row.index, idx ==   1       16

 – row.index, idx ==   12      16

 – row.index, idx ==   13      16

 – row.index, idx ==   14      16

 – row.index, idx ==   15      16

 – row.index, idx ==   16      16

 – row.index, idx ==   5       16

 – row.index, idx ==   4       16

I use idx to enter the values from the database into a table

for row in db:nrows("SELECT \* FROM main WHERE difficulty=" .. diff .. " ORDER BY status, topHeight DESC") do idx = idx + 1 dbRec[idx] = {} dbRec[idx].routeId = row.route\_id dbRec[idx].routeName = row.route\_name dbRec[idx].difficulty = row.difficulty dbRec[idx].status = row.climbed\_status dbRec[idx].topHeight = row.topHeight ...

        tableView:insertRow

            {

                isCategory = isCategory,

                rowHeight = rowHeight,

                rowColor = rowColor,

                --lineColor = lineColor,

            }

end

So how about you save the idx in with the row data when you create it?

For a single variable, on the insertRow() call, you can add the paramter to the row using the id field as so:

tableView:insertRow

            {

                isCategory = isCategory,

                rowHeight = rowHeight,

                rowColor = rowColor,

                id = idx,

                --lineColor = lineColor,

            }

end

Then in your onRowRender, you can get the correct idx for the row using row.id (which is holding your idx var for the row). There’s also a params(?) field you can add to the row as well if you need more data than just one item.

Great, its working. Thank you mpappas, very much for all your effort.

This was the only post I could find, not effectively a bug but something which isn’t aspheric, in tableview, is it me but the lines drawn on the table view have a added line drawn over them depending on what colour you define the lines. I’ve noticed that it is offsetted to the right making the lines look a bit crap if I’m honest. Anyone experience the same issue?

I would guess it’s an issue with the relation between row.index used in most cases, and [idx], which it is not clear at all how gets incremented.

Basically, it’s impossible to tell from this code if your indice “idx”, which must be just right every time through this code, whether it is set properly each time. Perhaps adding a print(" – row.index, idx == ", row.index, idx) would be helpful?

Yes. There is something wrong. As soon as I start scrolling idx doesn’t change anymore.

 – row.index, idx ==   1       1

 – row.index, idx ==   2       2

 – row.index, idx ==   3       3

 – row.index, idx ==   4       4

 – row.index, idx ==   5       5

 – row.index, idx ==   6       6

 – row.index, idx ==   7       7

 – row.index, idx ==   8       8

 – row.index, idx ==   9       9

 – row.index, idx ==   10      10

 – row.index, idx ==   11      11

 – row.index, idx ==   12      12

 – row.index, idx ==   13      13

 – row.index, idx ==   14      14

 – row.index, idx ==   15      16

 – row.index, idx ==   16      16

 – row.index, idx ==   3       16

 – row.index, idx ==   2       16

 – row.index, idx ==   1       16

 – row.index, idx ==   12      16

 – row.index, idx ==   13      16

 – row.index, idx ==   14      16

 – row.index, idx ==   15      16

 – row.index, idx ==   16      16

 – row.index, idx ==   5       16

 – row.index, idx ==   4       16

I use idx to enter the values from the database into a table

for row in db:nrows("SELECT \* FROM main WHERE difficulty=" .. diff .. " ORDER BY status, topHeight DESC") do idx = idx + 1 dbRec[idx] = {} dbRec[idx].routeId = row.route\_id dbRec[idx].routeName = row.route\_name dbRec[idx].difficulty = row.difficulty dbRec[idx].status = row.climbed\_status dbRec[idx].topHeight = row.topHeight ...

        tableView:insertRow

            {

                isCategory = isCategory,

                rowHeight = rowHeight,

                rowColor = rowColor,

                --lineColor = lineColor,

            }

end

So how about you save the idx in with the row data when you create it?

For a single variable, on the insertRow() call, you can add the paramter to the row using the id field as so:

tableView:insertRow

            {

                isCategory = isCategory,

                rowHeight = rowHeight,

                rowColor = rowColor,

                id = idx,

                --lineColor = lineColor,

            }

end

Then in your onRowRender, you can get the correct idx for the row using row.id (which is holding your idx var for the row). There’s also a params(?) field you can add to the row as well if you need more data than just one item.

Great, its working. Thank you mpappas, very much for all your effort.

This was the only post I could find, not effectively a bug but something which isn’t aspheric, in tableview, is it me but the lines drawn on the table view have a added line drawn over them depending on what colour you define the lines. I’ve noticed that it is offsetted to the right making the lines look a bit crap if I’m honest. Anyone experience the same issue?