TableView Row not working
I have a data hardcoded with 8 objects.When i dynamically change the data it's not working.Here is the code.Please help.
function setCheckBox(){
var data2 = [];
for (var i=0;i<9;i++)
{
var row = Titanium.UI.createTableViewRow();
var l1 = Titanium.UI.createLabel({ text:'Label ' + i });
row.add(l1);
data2.push(row);
}
tableview.setData(data2);
}
// create table view event listener
tableview.addEventListener('click', function(e)
{
setCheckBox();
Titanium.API.info(" Text = " + e.rowData.title);
});
2 Answers
-
A TableView click is fired when a row with data is clicked. An empty table wouldn't generate a click because there are no rows of data. Since you are creating your rows inside the click, there are none to click when the TableView is created so nothing appears to happen. If you move the setCheckBox outside the click like I have shown below, you will get a table with data that responds to clicks.
My second note is that you haven't set a title when you created the rows so the log function would return an empty title.
function setCheckBox(){ var data2 = []; for (var i=0;i<9;i++) { var row = Titanium.UI.createTableViewRow(); var l1 = Titanium.UI.createLabel({ text:'Label ' + i }); row.add(l1); data2.push(row); } tableview.setData(data2); } setCheckBox(); // create table view event listener tableview.addEventListener('click', function(e) { Titanium.API.info(" Text = " + e.rowData.title); });
-
I had this problem, it was because the id I was using e.rowData.description may be reserved. I changed this to e.rowData.memo and it all suddenly worked. So maybe title is also reserved, try changing this.