Because the photos are on an external server, I want to show the tableview first, then while I allow the user to scroll up and down the tableview, I start loading the photos and make them pop up on the rows as they are downloaded.
In the network listener, when each photo has been received, I redraw the whole scene, then load the next photo.
The problem is that when redrawing the scene, I call widget.newTableView(), the Y position of the tableview is reset to 0, which will be a constant annoyance to the user for as long as the downloading goes on.
I thought about quickly storing and restoring the Y position when redrawing the scene. But will the scrolling momentum be kept, or will it be reset to zero?
[lua]
local y = list:getContentPosition()
list = widget.newTableView()
list:scrollToY(y, 0)
[/lua]
Is there a way to make the photos pop up on the rows without redrawing the whole scene?
Just create a function (like the one below) and call it from network listener passing the index of the row that will receive the photo and the photo filename to be loaded.
The code below is using widget v2.0 and assumes that you have inserted your tableView inside a group display (like the one used in the Storyboard).
[lua]
local function updateRowImage(rowIndex, photoFilename)
local tableViewObj = group[“tableView”]
local row = tableViewObj._view._rows[rowIndex]
local rowImage = display.newImage(photoFilename, system.TemporaryDirectory)
Just create a function (like the one below) and call it from network listener passing the index of the row that will receive the photo and the photo filename to be loaded.
The code below is using widget v2.0 and assumes that you have inserted your tableView inside a group display (like the one used in the Storyboard).
[lua]
local function updateRowImage(rowIndex, photoFilename)
local tableViewObj = group[“tableView”]
local row = tableViewObj._view._rows[rowIndex]
local rowImage = display.newImage(photoFilename, system.TemporaryDirectory)