TableView row id

Hello,

Sorry for probably asking an elementary question… I have a tableview to which I want to add and delete rows through (non in-row) buttons, my question is: how can I get the last row id (or index) to be used from outside of the onRowRender function??

I need it to delete the last row added, in a ‘dynamic way’… So far I’m only managing to get the id of the first row I am adding… Hope I’m being clear enough.

Thank you!!!

Perhaps tableView.getNumRows() will take care of you.

See: http://docs.coronalabs.com/api/type/TableViewWidget/getNumRows.html

Rob

Very cool,

thanks Rob!

now, from that same last row I’m trying to extrapolate a variable contained in it but by using  this:

    tableView.row[tableView:getNumRows()].textNumber.text 

I get the error: “attempting to index the field ‘row’ (a nil value)”.

Can you illimunate on a functional method to do that??

Thanks a lot…
 

Corona SDK does not provide direct access to the rows that way.  In your onRowRender function you will get access to that row.

If you are unfamiliar with the “Model-View-Controller (MVC)” pattern of programming, you should read about it.  In a simplified explanation, the “Model” is the data your using.  The “View” is how it’s displayed.  The “Controller” is the bridge between the View and the Model.  In our implementation, the tableView is the view.  The data involved is how to display that data.  Because of this you only need to know the current row to render it.  If you need to make data based decisions, then you should do that based on the data and manipulate the data accordingly, then tell the tableView to render the current data.

In other words, don’t use the tableView as your data source.  In many cases, you would just update your data then removeAllRows() and then reload the table from scratch.

Rob

I read a bit about it.

So there’s just no way to utilize in-row generated data (a simple number in this case) from outside of the onRowRender function??

There is not a supported way.  Store the data in an outside data structure of your choice. This is really the best way.

Rob

Storing the data into a table keyed by the the tablview row indexes is working fine…

Thanks a lot Rob!!

I agree with Rob: it’s a mistake to try to store data in a tableview and access it directly. Your data should reside externally.

Perhaps tableView.getNumRows() will take care of you.

See: http://docs.coronalabs.com/api/type/TableViewWidget/getNumRows.html

Rob

Very cool,

thanks Rob!

now, from that same last row I’m trying to extrapolate a variable contained in it but by using  this:

    tableView.row[tableView:getNumRows()].textNumber.text 

I get the error: “attempting to index the field ‘row’ (a nil value)”.

Can you illimunate on a functional method to do that??

Thanks a lot…
 

Corona SDK does not provide direct access to the rows that way.  In your onRowRender function you will get access to that row.

If you are unfamiliar with the “Model-View-Controller (MVC)” pattern of programming, you should read about it.  In a simplified explanation, the “Model” is the data your using.  The “View” is how it’s displayed.  The “Controller” is the bridge between the View and the Model.  In our implementation, the tableView is the view.  The data involved is how to display that data.  Because of this you only need to know the current row to render it.  If you need to make data based decisions, then you should do that based on the data and manipulate the data accordingly, then tell the tableView to render the current data.

In other words, don’t use the tableView as your data source.  In many cases, you would just update your data then removeAllRows() and then reload the table from scratch.

Rob

I read a bit about it.

So there’s just no way to utilize in-row generated data (a simple number in this case) from outside of the onRowRender function??

There is not a supported way.  Store the data in an outside data structure of your choice. This is really the best way.

Rob

Storing the data into a table keyed by the the tablview row indexes is working fine…

Thanks a lot Rob!!

I agree with Rob: it’s a mistake to try to store data in a tableview and access it directly. Your data should reside externally.