I’m having an odd issue with tableveiew. I have an app that calls mulitple storyboard scenes. Many of them have tableviews using code similiar to below. They are all loaded using sqlite databases. This works fine. In fact, they ALL work fine… _ as long as they are the first scene I visit _.
When I visit any subsequent scenes with tableviews, the data is there, but it starts near the bottom of the tableview area with white space where the data SHOULD be. If I nudge it or drag and let go, it springs back up to where it SHOULD start.
It’s weird because whichever one I visit first works fine…
Any ideas? Hopefully… a fix or work around?
Thanks!
John
--------------------------------------------------------------------------------- -- SCENE NAME -- Scene notes go here --------------------------------------------------------------------------------- require "sqlite3" local globals = require( "globals" ) local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require( "widget" ) local ALSBLS = "ALS" -- Clear previous scene storyboard.removeAll() -- local forward references should go here -- --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- Background color local bgImage = display.newRect( 0, 0, 380, 570 ) bgImage.strokeWidth = 0 bgImage:setFillColor( 0/255, 84/255, 166/255 ) bgImage:setStrokeColor( 0/255, 84/255, 166/255 ) bgImage.x = display.contentCenterX bgImage.y = display.contentCenterY group:insert(bgImage) -- Header 360 x 50 local bgHeader = display.newRect( 0, 0, 360, 50 ) bgHeader.strokeWidth = 0 bgHeader:setFillColor( 237/255, 237/255, 237/255 ) bgHeader:setStrokeColor( 237/255, 237/255, 237/255 ) bgHeader.x = display.contentCenterX bgHeader.y = 25 group:insert(bgHeader) local topText = display.newText( "Drugs", 20, 0, native.systemFontBold, 20 ) topText:setFillColor( 0 ) topText.y = 25 topText.x = display.contentCenterX group:insert(topText) -- back button local backBtn = display.newImage( "back.png" ) backBtn.x = 25 backBtn.y = 25 backBtn:addEventListener( "tap", function( event ) storyboard.gotoScene( "scene\_menu" ) end ) group:insert( backBtn) -- top Phone button local imgPhone = display.newImage( "callmain.png" ) imgPhone.x = display.contentWidth - 50 imgPhone.y = 25 imgPhone:addEventListener( "tap", function( event ) system.openURL( "tel:610-402-1473" ) end ) group:insert(imgPhone) -- -- -- local navBarHeight = 60 local tabBarHeight = 0 -- data local myDataD = {} --local myData = {}; local int = 1 local doneDB = false local path = system.pathForFile("EMS\_DB.sqlite", system.DocumentsDirectory ) file = io.open( path, "r" ) if( file == nil )then -- Doesn't Already Exist, So Copy it In From Resource Directory pathSource = system.pathForFile( "EMS\_DB.sqlite", system.ResourceDirectory ) fileSource = io.open( pathSource, "rb" ) contentsSource = fileSource:read( "\*a" ) --Write Destination File in Documents Directory pathDest = system.pathForFile( "EMS\_DB.sqlite", system.DocumentsDirectory ) fileDest = io.open( pathDest, "wb" ) fileDest:write( contentsSource ) -- Done io.close( fileSource ) io.close( fileDest ) end -- handle the applicationExit event to close the db local function onSystemEvent( event ) if( event.type == "applicationExit" and doneDB==false) then db:close() end end function reLoadData() print ("reLoadData") int = 1 myDataD = {} doneDB = false local mySQL mySQL = "SELECT DrugName from Drug\_Master Order By DrugName" print(mySQL) --Go through my database selecting all the site names... local dbPath = system.pathForFile("EMS\_DB.sqlite", system.ResourceDirectory) local db = sqlite3.open( dbPath) for row in db:nrows(mySQL) do myDataD[int]={} myDataD[int].name = row.DrugName int = int+1 end db:close() doneDB = true print(int) end reLoadData() local springStart = 0 local needToReload = false -- ------------------------------------------------------------------------ -- -- ------------------------------------------------------------------------ local function scrollListener( event ) local buffer = 50 local phase = event.phase local row = event.target local params = event.target.params if event.phase == "began" and not row.selected then startXpos = event.x startYpos = event.y row.selected = true elseif phase == "ended" or phase == "moved" then row.selected = false if phase == "ended" and event.y \< startYpos + buffer and event.y \> startYpos - buffer and event.x \< startXpos + buffer and event.x \> startXpos - buffer then --native.showAlert("Row " .. row.index, "Selected") if params == nil then print("category") else print ("Row " .. params.sub .. " Selected " .. params.name) end end end return true end -------------------------------------------------------------------------------------- --ON ROW TOUCH -------------------------------------------------------------------------------------- local function onRowTouch(event) return true end -------------------------------------------------------------------------------------- local function onRowRender( event ) --Set up the localized variables to be passed via the event table local row = event.row local id = row.index local params = event.row.params local idx if ( event.row.params ) then idx = params.idx --row.bg = display.newRect( 0, 0, display.contentWidth, 55 ) row.bg = display.newImageRect( "Hospitalcell.png", display.contentWidth, 55 ) row.bg.anchorX = 0 row.bg.anchorY = 0 --row.bg:setFillColor( 0/255, 84/255, 166/255 ) --row.bg:setStrokeColor( 0/255, 84/255, 166/255 ) row:insert( row.bg ) --row.imgArrow = display.newImageRect( "sidearrow.png", display.contentWidth, 55 ) --row.imgArrow.anchorX = 0 --row.imgArrow.anchorY = 0 --row.imgArrow.x = display.contentWidth - 20 --row.imgArrow.y = 10 row.nameText = display.newText( params.name, 16, 0, native.systemFontBold, 20 ) row.nameText.anchorX = 0 row.nameText.anchorY = 0 row.nameText:setFillColor( 1 ) row.nameText.y = 18 row.nameText.x = 10 row:insert( row.nameText ) row.imgArrow = display.newImageRect( "sidearrow.png", 12, 20 ) row.imgArrow.anchorX = 0 row.imgArrow.anchorY = 0 row.imgArrow.x = display.contentWidth - 20 row.imgArrow.y = 18 row:insert(row.imgArrow) end return true end local myListD = widget.newTableView { top = navBarHeight + 30, width = display.contentWidth, height = display.contentHeight - navBarHeight - tabBarHeight, onRowRender = onRowRender, onRowTouch = onRowTouch, listener = scrollListener } ---------------------------------------------------------- -- Load table function ---------------------------------------------------------- function loadTable() myListD:deleteAllRows() local currentCat = "none" for i = 1, #myDataD do myListD:insertRow{ rowHeight = 55, isCategory = false, rowColor = {0/255, 84/255, 166/255 }, lineColor = { 0/255, 70/255, 130/255 }, params = { name = myDataD[i].name, isCat = false } } end end --------------------------------------------------------- -- Load Table --------------------------------------------------------- loadTable() group:insert( myListD ) group.x = display.contentCenterX group.y = display.contentCenterY end -- Called BEFORE scene has moved onscreen: function scene:willEnterScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view end -- Called AFTER scene has finished moving offscreen: function scene:didExitScene( event ) local group = self.view end -- Called prior to the removal of scene's "view" (display view) function scene:destroyScene( event ) local group = self.view end -- Called if/when overlay scene is displayed via storyboard.showOverlay() function scene:overlayBegan( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() function scene:overlayEnded( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "didExitScene" event is dispatched after scene has finished transitioning out scene:addEventListener( "didExitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) -- "overlayBegan" event is dispatched when an overlay scene is shown scene:addEventListener( "overlayBegan", scene ) -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed scene:addEventListener( "overlayEnded", scene ) --------------------------------------------------------------------------------- return scene