Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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);
});

— asked October 15th 2010 by Jacob John
  • iphone
0 Comments

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); 
    });
    
    — answered October 15th 2010 by John McKnight
    permalink
    5 Comments
    • No actually the code starts like this.
      var data = [
      {title:'Calculate ',hasCheck:true},
      {title:'Entertainment'},
      {title:'Games'},
      {title:'News'},
      {title:'Productivity'},
      {title:'Search Tools'},
      {title:'Social Networking'},
      {title:'Sports'},
      {title:'Travel'}
      ];
      var tableview = Titanium.UI.createTableView({
      data:data,
      style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
      top:45
      });
      Then what's the problem

      — commented October 15th 2010 by Jacob John
    • Knowing that would have helped…

      What isn't working? When I put that code together I get a list of items that I can click and see change.

      — commented October 15th 2010 by John McKnight
    • I am getting info like this
      [INFO] data = [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
      [INFO] data2 = [object TiUITableViewRow],[object TiUITableViewRow],[object TiUITableViewRow],[object TiUITableViewRow],[object TiUITableViewRow],[object TiUITableViewRow],[object TiUITableViewRow],[object TiUITableViewRow],[object TiUITableViewRow]

      what's the difference?

      — commented October 15th 2010 by Jacob John
    • First time I also get the list but need to add a checkbox when i click on a particular row.
      when i used the above code it's becoming blank.what mat be the reason.Please see the INFO I am getting for two arrays 'data' and 'data2'

      — commented October 15th 2010 by Jacob John
    • Here, how to get all data from " data2 [ ] " can u explain ?

      — commented February 5th 2014 by Deepankar Katiyar
  • 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.

    — answered January 31st 2012 by Tushar Joshi
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.