TableViews and custom named labeled rows.

Hello all!

So I can be incredibly dense, so we have that to work with…but I’m missing the way to “pass” a variable to the “onRender” method? I mean, I want to insert new rows that AREN’T statically defined in a pre-existing table.

For example, I got a pubnub lobby going, and as new players appear in the lobby, I’d really like to add them to my tableview list thingy:

 local function onRowRender( event )  
 local row = event.row  
 local rowGroup = event.view  
 local label = "Row ("  
 local color = 0  
  
 if row.isCategory then  
 label = "Category (";  
 color = 255  
 end  
  
 row.textObj = display.newRetinaText( rowGroup, label .. row.index .. ")", 0, 0, native.systemFont, 16 )  
 row.textObj:setTextColor( color )  
 row.textObj:setReferencePoint( display.CenterLeftReferencePoint )  
 row.textObj.x, row.textObj.y = 20, rowGroup.contentHeight \* 0.5  
 end  

Now in the " label … row.index … “)”" part, how the hell would I assign it like a new label like playerName or id# or ANYTHING arbitrary? I’m just not wrapping my head around it.

Appreciate any help in advance!!

-Mario [import]uid: 11636 topic_id: 24551 reply_id: 324551[/import]

When you call insertRow, you can give the row an id, which is a string. Then you can use that string in the onRowRender to get specific information about that row.
For example,

[lua]local peeps = {}
peeps[1] = “jim”
peeps[2] = “ted”

local function onRowRender(event)
–same code as your example, except
local label = row.id --this will be “jim” or “ted”
end
for i=1,#peeps do
myTableView:insertRow{
id = peeps[i],
onRender = onRowRender,
}
}[/lua]

additionally, you can use that id as a lookup to get other info. For example, if row.id is “jim”, then you can set the color of your row to red or soemhting.
Make sense? [import]uid: 115687 topic_id: 24551 reply_id: 102866[/import]

Yes! Yes it does. Thanks!

-Mario

PS I was wondering if I dreamt I posted this question or not, I couldn’t find my way back to it!! :slight_smile: [import]uid: 11636 topic_id: 24551 reply_id: 102886[/import]