Removing scrollView?

Hi guys,

Recently started tinkering with Corona. I’m a pretty experienced C++ dev (experienced from a student perspective anyway!) and have got myself a bunch of tabs on the go using a tabBar.

In the third tab I’m creating a scrollView and adding an image to it. When I leave the tab I want to delete the scrollView. However, despite my best efforts, I’m having no success.

Inside scene:hide’s elseif phase == “did”, I’ve tried display:remove(scrollObject), scrollObject:removeSelf() etc. Not having much luck.

Is there something really elementary I’m missing here? I suspect so.

Any pointers appreciated!

Cheers

Hi @Dezachu,

It mostly depends on how you set this whole thing up, and how you’re pointing to the scrollView object. Does each tab bring up a new scene, or is it one scene with a tabBar and other things happening all within that scene? If each tab opens/hides a scene, then you’ll need to make the scrollView object accessible to other scenes (other tabs) or Lua won’t know what you’re attempting to remove. There are various ways to make it accessible, i.e. store it a Composer variable, pass its reference between scenes, and other methods.

It also depends where you declared the scrollView in its own scene. If you declared it within one of the Composer functions like “:show()” then it won’t be accessible within “:hide()”, so you’d need to upvalue declare it.

Best regards,

Brent

Hey Brent, thanks for the reply.

I’ve merely opened up the default tabBar project template from within Corona itself. It does appear each view (or tab) creates a new scene (there’s a called to composer.newScene()). 

scrollView itself is just declared as a local in the Lua file for view3. Not within any functions - again, I just grabbed the code from the API to test and decided to roll with it!

Part of the problem is my unfamiliarity with Lua - best go find myself some learning material!

Cheers

Put something like ‘local scrollView’ at the top of your .lua file. Now the scrollView object is pre-declared so anything that comes below it in the code can access it.

When you create it, do:

[lua]

scrollView = widget.newScrollView…etc

[/lua]

then to remove:

[lua]

display.remove(scrollView)

scrollView = nil

[/lua]

Hi @Dezachu,

It mostly depends on how you set this whole thing up, and how you’re pointing to the scrollView object. Does each tab bring up a new scene, or is it one scene with a tabBar and other things happening all within that scene? If each tab opens/hides a scene, then you’ll need to make the scrollView object accessible to other scenes (other tabs) or Lua won’t know what you’re attempting to remove. There are various ways to make it accessible, i.e. store it a Composer variable, pass its reference between scenes, and other methods.

It also depends where you declared the scrollView in its own scene. If you declared it within one of the Composer functions like “:show()” then it won’t be accessible within “:hide()”, so you’d need to upvalue declare it.

Best regards,

Brent

Hey Brent, thanks for the reply.

I’ve merely opened up the default tabBar project template from within Corona itself. It does appear each view (or tab) creates a new scene (there’s a called to composer.newScene()). 

scrollView itself is just declared as a local in the Lua file for view3. Not within any functions - again, I just grabbed the code from the API to test and decided to roll with it!

Part of the problem is my unfamiliarity with Lua - best go find myself some learning material!

Cheers

Put something like ‘local scrollView’ at the top of your .lua file. Now the scrollView object is pre-declared so anything that comes below it in the code can access it.

When you create it, do:

[lua]

scrollView = widget.newScrollView…etc

[/lua]

then to remove:

[lua]

display.remove(scrollView)

scrollView = nil

[/lua]