Textfield persists in other scene

Hello,

I have a scene with a table view, each row contains a textfield used to title the row, the textfield is always accessable and never gets removed. The problem is that when I go to another scene every row’s textfield persists and still can be interacted with in this other scene.

I have read about native objects and how they must be removed manually outside of composer functions, but how I can I approach this matter in this case? Since my textfields are inside of a tableview (they’re generated inside of the onRowRender function) their removal cannot be displayed say on hideScene… also, for how the app is designed, I cannot destroy the scene in question.

Any idea??

Thanks!!!

Are you inserting the native.newTextField into the row’s group?

Rob

Hi Rob,

Yes it’s child of the row group. I guess that’s why it is hard to handle outside of onrowrender…

Can you post your onRowRender() code?

sure, this is just the interested part where the textfield is created and handled :

function onRowRender( event )     local row = event.row              local rowHeight = row.contentHeight     local rowWidth = row.contentWidth         local showInd = display.newText( row, namesContainer[row.index] or row.index, 0, 0, nil, 16 )     showInd.anchorX = 0.5              if showInd.text ==  tostring(row.index) then        showInd.x = 8      else        showInd.x = rowWidth / 2       end     showInd.y = rowHeight \* 0.2     showInd:setFillColor( 0.8 )     showInd.alpha = 0.7          local inputName = native.newTextField( 0, 0 , 158, 16 )           row:insert (inputName)                      inputName.anchorX = 0.5           inputName.x = rowWidth / 2           inputName.y = rowHeight \* 0.28           inputName.inputType = "default"           inputName:setTextColor(1, 1, 1 )           inputName.hasBackground = false           inputName.align = "center"           inputName.alpha = .8           inputName.strokeWidth = 2           inputName.strokeColor = { 30/255, 45/255, 1827/255 }       local function inHandler (event)                   transition.to (showInd, {alpha=0, time=100})         if (event.phase == "began") then           elseif (event.phase == "editing") then                        print ("editing " .. event.target.text)             elseif (event.phase == "ended") then                         print ("ended " .. event.target.text)                       native.setKeyboardFocus (nil)                       transition.to (showInd, {alpha=0.7, time=100})                       event.target.text = ""                            elseif (event.phase == "submitted") then                         print ("submitted " .. event.target.text)                      rowName = event.target.text                     if string.len( rowName ) \> 0 then                                             if string.len( rowName ) \> 24  then                       rowName = string.sub( rowName, 1, 24 )                       end                         namesContainer[row.index] = rowName                       showInd.text = rowName                       inputName.text = ""                                                  native.setKeyboardFocus (nil)                       transition.to (showInd, {alpha=0.7, x = rowWidth / 2, time=100})                     else                                            native.setKeyboardFocus (nil)                       transition.to (showInd, {alpha=0.7, time=100})                     end                              end                         end   inputName:addEventListener( "userInput", inHandler )     end

Hope it’s clear enough…

What version of Corona SDK are you using?

Rob

Version 2014.2511 (2014.11.18)

I just dropped this into a tableView and changing scenes removed them as expected.  But there are other problems, like them sitting above the rest of the Corona SDK display graphics, so if you have a banner at the top or a tab bar at the bottom, the text fields are just going to scroll over top of them until off screen rows are culled.

Rob

Hi Rob,

EDIT ---- I’m too noticing the texfield sitting over other scene elements es. bars above and below the tableview, and I don’t know why this occurs. However in the final version of the app the textfields are meant have the backgorund set to false, so at least at the moment this not a relevant problem. —

What concerns me is that they’re still not removed when changing scene. When you tested this did you remove the scene left (where the textfields are)? beacause as I said I cannot go for that option, the left scene must stay in memory as it is since first created.

Anyway even if you didn’t remove it I might see why the removal of the textfields was successfull in your case: the scene we’re moving to in my project gets loaded with the effect 'fromRight ', but still it is NOT an overlay scene, though loaded with said effect the textfields persist underneath it and can be interacted with. But if load the scene with, say, ‘slideLeft’ the persistance doens’t occur as if they’re pushed away from screen.

Unforntunately I design it this way and cannot change the effect from being ‘fromRight’. Maybe it’s something inside the code of that effect that’s causes this weird behavior??

native.newTextFields are “native” objects.  They are not part of the OpenGL canvas where all the display.* objects live.  You can’t mix the two.  Anything “native.*” will always be on top of anything done with display.* and widget.*.  This cannot be changed/fixed.  

Even though you plan to set the backgrounds to transparent, if they have content, they will slide over top of your other features.  In my test app, it was sliding the screen away.  One thing you can do, is in your scene:hide (will phase) set the visibility of the tableView to false.  This should cause all it’s children to also be set to invisible too.  You just have to make sure to set the visibility of the tableView to true in the scene:show (did phase).

Rob

Hi Rob,

I tried your suggestions, but the textfields remain on top of of everything regardless of setting the tableview to not visible or not hittable or else.

The only thing that seems to affect them it’s moving the tableview, so on sceneHide I make it transition on the x just enough to make the textfields go offscreen and delay the transition with a timer so that it occurs when the new scene already covers the previous.

Seems like a magician hand trick but so far it’s working, will post again if problems arise…

Thanks!

Are you inserting the native.newTextField into the row’s group?

Rob

Hi Rob,

Yes it’s child of the row group. I guess that’s why it is hard to handle outside of onrowrender…

Can you post your onRowRender() code?

sure, this is just the interested part where the textfield is created and handled :

function onRowRender( event )     local row = event.row              local rowHeight = row.contentHeight     local rowWidth = row.contentWidth         local showInd = display.newText( row, namesContainer[row.index] or row.index, 0, 0, nil, 16 )     showInd.anchorX = 0.5              if showInd.text ==  tostring(row.index) then        showInd.x = 8      else        showInd.x = rowWidth / 2       end     showInd.y = rowHeight \* 0.2     showInd:setFillColor( 0.8 )     showInd.alpha = 0.7          local inputName = native.newTextField( 0, 0 , 158, 16 )           row:insert (inputName)                      inputName.anchorX = 0.5           inputName.x = rowWidth / 2           inputName.y = rowHeight \* 0.28           inputName.inputType = "default"           inputName:setTextColor(1, 1, 1 )           inputName.hasBackground = false           inputName.align = "center"           inputName.alpha = .8           inputName.strokeWidth = 2           inputName.strokeColor = { 30/255, 45/255, 1827/255 }       local function inHandler (event)                   transition.to (showInd, {alpha=0, time=100})         if (event.phase == "began") then           elseif (event.phase == "editing") then                        print ("editing " .. event.target.text)             elseif (event.phase == "ended") then                         print ("ended " .. event.target.text)                       native.setKeyboardFocus (nil)                       transition.to (showInd, {alpha=0.7, time=100})                       event.target.text = ""                            elseif (event.phase == "submitted") then                         print ("submitted " .. event.target.text)                      rowName = event.target.text                     if string.len( rowName ) \> 0 then                                             if string.len( rowName ) \> 24  then                       rowName = string.sub( rowName, 1, 24 )                       end                         namesContainer[row.index] = rowName                       showInd.text = rowName                       inputName.text = ""                                                  native.setKeyboardFocus (nil)                       transition.to (showInd, {alpha=0.7, x = rowWidth / 2, time=100})                     else                                            native.setKeyboardFocus (nil)                       transition.to (showInd, {alpha=0.7, time=100})                     end                              end                         end   inputName:addEventListener( "userInput", inHandler )     end

Hope it’s clear enough…

What version of Corona SDK are you using?

Rob

Version 2014.2511 (2014.11.18)

I just dropped this into a tableView and changing scenes removed them as expected.  But there are other problems, like them sitting above the rest of the Corona SDK display graphics, so if you have a banner at the top or a tab bar at the bottom, the text fields are just going to scroll over top of them until off screen rows are culled.

Rob

Hi Rob,

EDIT ---- I’m too noticing the texfield sitting over other scene elements es. bars above and below the tableview, and I don’t know why this occurs. However in the final version of the app the textfields are meant have the backgorund set to false, so at least at the moment this not a relevant problem. —

What concerns me is that they’re still not removed when changing scene. When you tested this did you remove the scene left (where the textfields are)? beacause as I said I cannot go for that option, the left scene must stay in memory as it is since first created.

Anyway even if you didn’t remove it I might see why the removal of the textfields was successfull in your case: the scene we’re moving to in my project gets loaded with the effect 'fromRight ', but still it is NOT an overlay scene, though loaded with said effect the textfields persist underneath it and can be interacted with. But if load the scene with, say, ‘slideLeft’ the persistance doens’t occur as if they’re pushed away from screen.

Unforntunately I design it this way and cannot change the effect from being ‘fromRight’. Maybe it’s something inside the code of that effect that’s causes this weird behavior??

native.newTextFields are “native” objects.  They are not part of the OpenGL canvas where all the display.* objects live.  You can’t mix the two.  Anything “native.*” will always be on top of anything done with display.* and widget.*.  This cannot be changed/fixed.  

Even though you plan to set the backgrounds to transparent, if they have content, they will slide over top of your other features.  In my test app, it was sliding the screen away.  One thing you can do, is in your scene:hide (will phase) set the visibility of the tableView to false.  This should cause all it’s children to also be set to invisible too.  You just have to make sure to set the visibility of the tableView to true in the scene:show (did phase).

Rob