KitchenSink tableview.data.length not defined
Note: the title of this post should be tableview.data.length does not return the current number of rows.
Platform: Android, emulator, Ti 1.3.2
How can I determine the number of rows in a tableView at any given time?
An example in the KS at table_view_row_delete.js results in an exception after row 5 is deleted, because tableview.data.length-1 on line 52 always returns 4 (and after row 5 is deleted, id 4 no longer exists).
Inserting this code at line 49 and opening the delete row page will make the problem clear:
Ti.API.info('****************************');
Ti.API.info(typeof(tableview));
Ti.API.info(typeof(tableview.data));
Ti.API.info(typeof(tableview.data.length));
Ti.API.info('Number of table rows: '+tableview.data.length);
tableview.deleteRow(tableview.data.length-1);
Ti.API.info("deleting row");
Ti.API.info('Number of table rows: '+tableview.data.length);
Ti.API.info('****************************');
I'd appreciate it if some Ti people could confirm whether or not this is a bug, and whether there is a workaround?
Much appreciated
3 Answers
-
Accepted Answer
Also getting an error with tableview.data and tableview.getData().
On iOS it always returns 1 and I can't actually access/loop through the data.
-
This is an 1 year old question, but I found myself in trouble to get the answer for this problem, so this is what I did to work:
var row1 = Ti.UI.createTableViewRow({...}); (...) tableview.appendRow(row1); tableview.appendRow(row2); (...) Ti.API.info("Number of table rows: " + tableview.[0].rows.length);
-
Now with working link…
Number of rows in table