JSON/Tableview: How to combine the two? How to "layout" tablerows?

Thanks, Rob! Checking it out now.

So after trying to understand the blog post and the included code, I am unfortunately even more confused then before.

What I managed to get working so far is to download the data from my php file and story it into a txt file, after JSON decoding it.

I know that this works because it prints out the statements I choose to the console, but for some reason I keep getting a “nil” error whenever I try to display the same results in my table. I have a feeling that I am close to the solution, but still stumped here.

Here is the code if someone wants to point out what I am missing. Thank you in advance.

http://pastebin.com/5u8TiiCU

Can you post the error your getting along with the whole stack trace?  Without knowing where your getting the nil, its going to be really hard to look at the code and follow it.

Oh sorry, of course:

Runtime error
…na\shishan prealpha nov 2013\5\displayTableTest2.lua:33: attempt to index global ‘t’ (a nil value)
stack traceback:
        [C]: ?
        …na\shishan prealpha nov 2013\5\displayTableTest2.lua:33: in function
‘_onRowRender’
        ?: in function '_createRo

Though I see two issues.  One, the error you are reporting.  In onRowRender() how does it know what t is?  The table t is defined local to newDataListener.  This is what’s generating your error.

Secondly your inserting records into the tableView is happening before you get your data.  Remember network actions are asynchronous that is the call returns immediately and when the action completes the callback listener function is called when the data is ready.  The for i = 1, 10 do loop that holds your inserts needs to be more like for i = 1, #t do and should be where you are printing out those values in your network handler.

So scope t so that it exists so that onRowRender can see it and move your insert’s to the right place and you should be good to go.

Rob

Hey Rob, thanks a lot for your help so far, but I just can’t seem to get it right.

I tried making sure that the table functions only get called after the newDataListener ran its course, but I can’t figure out how to make the RowRenderer see my table and populate it right. Tried only printing the table to the console within the onRowRenderer but all it pastes is nil. Maybe I am way over my head on this. :confused:

I don’t think you’re in way over your head.  There are tons to learn about programming and you can’t get it all right away. 

An important part of learning to work with Lua is understanding basic programming concepts and a very important one when working with Lua is something called “Scope”.   Please watch this video and see if you understand your problem after watching it:

http://www.youtube.com/watch?v=2ATlcGP2zMY

Then come back and hopefully you will have your solution.

Rob