Scrollview can not be removed - stays on screen when changing scene

Hi all,

I’m working on a two-tabs app with on the first tab a scrollview. When I go to the second tab (= another scene / screen), the scrollview stays in its place and is not removed. I can see that the other scene is loading in the background, behind the scrollview. I’ve tried to remove the Scrollview with code like :removeSelf() and display.remove( scrollView), however, this either just does nothing Or I get an error code: Attempt to compare number with nil… Can anyone help?

Jules

Hi @j_lancee,

Most likely you forgot to insert the scrollView into the scene’s group. When changing scenes, only things inside the scene’s group will be auto-removed (except for “native” objects like webViews, text fields, etc. which can’t be inserted into groups). Anyway, just insert the scrollView into the scene’s group and it should be cleaned up on change.

Take care,

Brent

Thanks a lot Brent, this worked! I have one other question regarding new lines and \n:

I get text from a text file into my program but the \n new line symbol in these texts is somehow not recognized. I’ve tried to convert the text from the textfile after reading, but the \n symbol is never recognized and translated in a new line. It is just printed as ‘\n’, where a new line should come.

However, it is recognized when I define a string in the program itself containing the \n sequence. But I need the ones imported to be recognized. How can I accomplish this?

This is in my code for reading:

local lieds = {}

for line in file:lines() do

    lieds[i] = line

    i=i+1

end

In this code the \n is not recognized but printed in my program as \n instead of a new line.

But when I define a string like this and print the string, the \n code IS translated into a new line…:

local lieds = {}

lieds[1] = “bla bla \n bla bla”

lieds[2] = “etc \n etc”

I hope you can help!

Jules

The method file:lines() reads one line at a time, so it’s reading up to the newline and breaking the text at that point.  You will never get newlines in the middle of the text using file:lines().

Rob

Hi @j_lancee,

Most likely you forgot to insert the scrollView into the scene’s group. When changing scenes, only things inside the scene’s group will be auto-removed (except for “native” objects like webViews, text fields, etc. which can’t be inserted into groups). Anyway, just insert the scrollView into the scene’s group and it should be cleaned up on change.

Take care,

Brent

Thanks a lot Brent, this worked! I have one other question regarding new lines and \n:

I get text from a text file into my program but the \n new line symbol in these texts is somehow not recognized. I’ve tried to convert the text from the textfile after reading, but the \n symbol is never recognized and translated in a new line. It is just printed as ‘\n’, where a new line should come.

However, it is recognized when I define a string in the program itself containing the \n sequence. But I need the ones imported to be recognized. How can I accomplish this?

This is in my code for reading:

local lieds = {}

for line in file:lines() do

    lieds[i] = line

    i=i+1

end

In this code the \n is not recognized but printed in my program as \n instead of a new line.

But when I define a string like this and print the string, the \n code IS translated into a new line…:

local lieds = {}

lieds[1] = “bla bla \n bla bla”

lieds[2] = “etc \n etc”

I hope you can help!

Jules

The method file:lines() reads one line at a time, so it’s reading up to the newline and breaking the text at that point.  You will never get newlines in the middle of the text using file:lines().

Rob

Just like to say thanx Brent :slight_smile:

It solved my problem w widgets too

[lua]

sceneGroup:insert(tableView)

[/lua]

Just like to say thanx Brent :slight_smile:

It solved my problem w widgets too

[lua]

sceneGroup:insert(tableView)

[/lua]