A Fuse Powered Company

Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

when scrolling table view, the selected row was reset. How to keep selected status?
Started by nipon.ph Aug 02 2014 06:27 AM

3 replies to this topic

Best Answer Gremlin Interactive , 02 August 2014 - 03:17 PM

Set a variable that stores the row id that is currently selected.

When it comes back on screen (via row render) check if the rows id is equal to the selected rows id and if so, recolor it.

That's one way of doing it.

Hope this helps

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

nipon.ph

[GLOBAL: userInfoPane.html]
nipon.ph
  • Starter
  • PipPip
  • 21 posts
  • Member

Hi Everyone,
 
Let me explain about the problem.
 
The row will be selected by Pressing or Tap at the row.
After row touch, if row.nameText.isselected is false,  color of bg (rect object) will be changed to blue color (selected row) but If row.nameText.isselected is true,  the color of bg (rect object) will be changed to write color (unselected row). It working fine.
 
but the problem is when I try to scroll table view down, some of selected row(blue color) will be changed to white color (unselect)  (it may be redraw the screen again, I don't know about tableview behaviour).
 
This is my code below. Could you suggest me the solution for this ? How can I retain the selected row, when tableview is scrolled down or up. Thank you very much
 
local function onRowTouch( event )
    local phase = event.phase
    local row = event.target
    local params = event.target.params
    
if event.phase == 'press' or event.phase == 'tap' then
         row.nameText.isselected = not row.nameText.isselected
         if(row.nameText.isselected) then
             row.nameText:setFillColor( 1, 1, 1 )       
              row.bg:setFillColor( 0.0, 0.58, 0.90)      ----- Select Row Here
         else
              row.nameText:setFillColor(0, 139/255, 166/255)
            row.bg:setFillColor( 1, 1, 1)    ----- Unselect Row Here
    end
   
 
end
 
local function onRowRender( event )
    local phase = event.phase
    local row = event.row
  local params = event.row.params
 
    row.bg = display.newRect( 0, 0, display.contentWidth+40, 30 )
    row.bg.anchorX = 0
    row.bg.anchorY = 0
    row.bg:setFillColor(1,1,1)
    row:insert(row.bg)
 
if (row.params) then    
      row.nameText = display.newText(params.name, 0,0, fontNameRegular, 14 )
      row.nameText.anchorX = 0
      row.nameText.anchorY = 0.5
      row.nameText:setFillColor(0, 139/255, 166/255)
      row.nameText.y =  30/2 -1
      row.nameText.x = 30 + display.screenOriginX
      row.nameText.id = params.id
      row.nameText.isselected = params.isselected
      row:insert(row.nameText)
 
   end
 
end


[TOPIC: post.html]
#2

Gremlin Interactive

[GLOBAL: userInfoPane.html]
Gremlin Interactive
  • Enterprise
  • PipPipPipPipPipPip
  • 700 posts
  • Jedi

  Best Answer

Set a variable that stores the row id that is currently selected.

When it comes back on screen (via row render) check if the rows id is equal to the selected rows id and if so, recolor it.

That's one way of doing it.

Hope this helps

[TOPIC: post.html]
#3

nipon.ph

[GLOBAL: userInfoPane.html]
nipon.ph
  • Starter
  • PipPip
  • 21 posts
  • Member

Set a variable that stores the row id that is currently selected.

When it comes back on screen (via row render) check if the rows id is equal to the selected rows id and if so, recolor it.

That's one way of doing it.

Hope this helps

 

Thank you very much. It's working! :)



[TOPIC: post.html]
#4

Gremlin Interactive

[GLOBAL: userInfoPane.html]
Gremlin Interactive
  • Enterprise
  • PipPipPipPipPipPip
  • 700 posts
  • Jedi

Thank you very much. It's working! :)


Glad to hear it. Happy coding :)


[topic_controls]
[/topic_controls]