Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

setFillColor messing with scroll
Started by ads_96 Jan 29 2019 11:19 AM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ads_96

[GLOBAL: userInfoPane.html]
ads_96
  • Observer

  • 8 posts
  • Corona SDK

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?

 

 

Attached File  scroll.PNG   9.89KB   0 downloads



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,803 posts
  • Corona SDK

We'd need to see some code.

[TOPIC: post.html]
#3

ads_96

[GLOBAL: userInfoPane.html]
ads_96
  • Observer

  • 8 posts
  • Corona SDK

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



[topic_controls]
[/topic_controls]