How to delete all child views in ScrollView or TableView

@Rob: Your suggestion seems to involve coming from a previous scene (“A”) to the current scene (“B”).

My situation is: I am looking at scene “B”, and I want to refresh scene “B”, without going to any other scenes.

I assume the solution is something like this:

  1. Delete all views in the current scene. 2. Call scene:createScene() to re-create the scene

Hope someone knows the answer to this one as it will solve a showstopper. [import]uid: 73434 topic_id: 34328 reply_id: 136600[/import]

Look at the storyboard.reloadScene() API call and see if that does what you want it to. Pay attention to the discussion on what’s needed to get createScene() to be triggered:

http://docs.coronalabs.com/api/library/storyboard/reloadScene.html
[import]uid: 199310 topic_id: 34328 reply_id: 136667[/import]

@Rob: When running storyboard.reloadScene(), only exitScene() and willEnterScene() are called. createScene() is never called. Is this a bug, or what am I doing wrong?

willExitScene: NO
exitScene: YES
createScene: NO
willEnterScene: YES
enterScene: NO

[lua]local scene = storyboard.newScene()
local fontSize = 20

function scene:createScene(event)

print(“createScene”)

local group = self.view

local function onRedraw(event)
if event.phase == “ended” then
fontSize = fontSize + 3
print(“fontSize:”, fontSize)
group = nil – documentation says createScene() is only called if scene’s view display group does not exist, so trying to nil it here (with no luck though)
storyboard.reloadScene()
end
return true
end

local text = display.newText(“Click to increase font size”, 0, 240, 320, 480, native.systemFont, fontSize)
text:addEventListener(“touch”, onRedraw)
group:insert(text)

end

function scene:willEnterScene(event)
print(“willEnterScene”)
end

function scene:enterScene(event)
print(“enterScene”)
end

function scene:willExitScene(event)
print(“willExitScene”)
end

function scene:exitScene(event)
print(“exitScene”)
storyboard.purgeScene()
end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“willEnterScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“willExitScene”, scene)
scene:addEventListener(“exitScene”, scene)

return scene[/lua]

Update: The following technique seems to reload the scene successfully. Unless someone can come up with a way of making reloadScene() work, I’ll go for this one.

[lua]local group = scene.view
for i=group.numChildren, 1, -1 do
display.remove(group[i])
group[i] = nil
end
scene:createScene() [/lua]

[import]uid: 73434 topic_id: 34328 reply_id: 136692[/import]

What build are you running. In 985 was this ditty:

Fixes issue with storyboard scene events firing in an incorrect order. As reported here: https://developer.coronalabs.com/forum/2012/11/15/order-storyboard-callbacks-willenterscene-and-didexitscene-has-changed#comment-form

So this should not be an issue with later versions. Are you running 985 or later? [import]uid: 199310 topic_id: 34328 reply_id: 136729[/import]

This happened in 996. Which results do you get if you run my code? [import]uid: 73434 topic_id: 34328 reply_id: 136748[/import]

I’m seeing the same thing. This is very likely a bug. Can you build a small project and post a bug report using the “Report a Bug” link above.

The documentation and what we are observing is at a minimum inconsistent. [import]uid: 199310 topic_id: 34328 reply_id: 136787[/import]

Reported as Bug #19869.
[import]uid: 73434 topic_id: 34328 reply_id: 136821[/import]