I have a line of code that sets the text of a selected row in a tableview to a lighter colour. Because of this, whenever I try to scroll through the tableview it tries to call it and an error pops up.
Any suggestions?
I have a line of code that sets the text of a selected row in a tableview to a lighter colour. Because of this, whenever I try to scroll through the tableview it tries to call it and an error pops up.
Any suggestions?
We’d need to see some code.
local function has\_value(arr, val) for index, value in ipairs(arr) do if value == val then return true end end return false end local function onRowRender( event ) local row = event.row local rowHeight = row.contentHeight local rowWidth = row.contentWidth local present = '' if (row.params.InLibrary == 0) then present = 'Checked out' else present = 'In Library' end local rowText = display.newText( row, row.params.AuthorLastName .. ' ' .. row.params.AuthorFirstName .. ' ' .. row.params.Title .. ' ' .. present, 0, 0, nil, 24 ) if has\_value(selected, row.params.ID) then rowText:setFillColor(0.7) else rowText:setFillColor(0) end rowText.anchorX = 0 rowText.x = 0 rowText.y = rowHeight \* 0.5 end local function onRowTouch( event ) local ind = {} local row = event.row if has\_value(selected, row.params.ID) then for k,v in ipairs(selected) do ind[v] = k end table.remove(selected, ind[row.params.ID]) else table.insert(selected, row.params.ID) end searchThisBook() end local tableView = widget.newTableView( { left = 50, top = 250, height = 400, width = 650, onRowTouch = onRowTouch, onRowRender = onRowRender, } )
function searchThisBook() tableView:deleteAllRows() current = {} for row in db:nrows( [[SELECT \* FROM books WHERE title LIKE "%]] .. bookTitle .. [[%" ORDER BY author\_last\_name]] ) do local rowParams = { ID = row.id, Title = row.title, AuthorFirstName = row.author\_first\_name, AuthorLastName = row.author\_last\_name, InLibrary = row.in\_library, } tableView:insertRow( { rowHeight = 50, params = rowParams, } ) table.insert(current, row.id) end end
We’d need to see some code.
local function has\_value(arr, val) for index, value in ipairs(arr) do if value == val then return true end end return false end local function onRowRender( event ) local row = event.row local rowHeight = row.contentHeight local rowWidth = row.contentWidth local present = '' if (row.params.InLibrary == 0) then present = 'Checked out' else present = 'In Library' end local rowText = display.newText( row, row.params.AuthorLastName .. ' ' .. row.params.AuthorFirstName .. ' ' .. row.params.Title .. ' ' .. present, 0, 0, nil, 24 ) if has\_value(selected, row.params.ID) then rowText:setFillColor(0.7) else rowText:setFillColor(0) end rowText.anchorX = 0 rowText.x = 0 rowText.y = rowHeight \* 0.5 end local function onRowTouch( event ) local ind = {} local row = event.row if has\_value(selected, row.params.ID) then for k,v in ipairs(selected) do ind[v] = k end table.remove(selected, ind[row.params.ID]) else table.insert(selected, row.params.ID) end searchThisBook() end local tableView = widget.newTableView( { left = 50, top = 250, height = 400, width = 650, onRowTouch = onRowTouch, onRowRender = onRowRender, } )
function searchThisBook() tableView:deleteAllRows() current = {} for row in db:nrows( [[SELECT \* FROM books WHERE title LIKE "%]] .. bookTitle .. [[%" ORDER BY author\_last\_name]] ) do local rowParams = { ID = row.id, Title = row.title, AuthorFirstName = row.author\_first\_name, AuthorLastName = row.author\_last\_name, InLibrary = row.in\_library, } tableView:insertRow( { rowHeight = 50, params = rowParams, } ) table.insert(current, row.id) end end