Titanium Community Questions & Answer Archive

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

Custom TableView Rows, events not working?

Alright so using this guide, it seems that the event properties (Such as "e.rowData.__" and "e.index") do not work when using an EventListener, and I don't understand why not.

Like using the exact script that guide uses, if you try adding an EventListener and using the rowdata, it won't work.

If you need to look at the script, you can find it here.

— asked September 6th 2010 by Colton Arabsky
  • tableview
0 Comments

5 Answers

  • Accepted Answer

    Your real code suffers from the same problem.

    The row objects for your table are not stored in the CustomData array.

    The row objects are created during the main loop and are stored in the data array. The elements of the CustomData array are only used to provide the text for the labels that are added to each row object.

    If you don't set custom properties on the row objects themselves, the only way to access the values of the text for the labels is by referring to e.row.children[x].text.

    — answered September 7th 2010 by James K
    permalink
    1 Comment
    • Oh my, thank you!! This is exactly what I needed :D Sorry it took so lonf to explain what my problem was and everything, I was sort of busy and confused and really unorganized, but you answered my question and I thank you; I could not for the life of me get it to display what I wanted. Thanks James! :)

      — commented September 7th 2010 by Colton Arabsky
  • I'm the author of this tutorial. I don't see any event handling in your code.

    — answered September 6th 2010 by Dan Tamas
    permalink
    0 Comments
  • Of course there isn't, because that is the code in your tutorial, in the download link. Nothing added, nothing removed.

    What I'm asking is if there is anything in there that would stop Event handling from working, such as something like:

    TheTable.addEventListener('click', function(e)
    {
        var win = null;
        win = Ti.UI.createWindow({title:e.rowData.title, url:e.rowData.link});
        Titanium.UI.currentTab.open(win,{animated:true});
    });
    
    — answered September 6th 2010 by Colton Arabsky
    permalink
    0 Comments
  • The problem is that you are referencing e.rowData.title when title has not been defined as a row property. The row objects in the code to which you've referred do not have any custom properties.

    You need to either set properties manually in the loop:

    row.country = CustomData[i].country;

    Or reference the values of the objects added to the row:

    Ti.API.info('The country for this row event is ' + e.row.children[1].text);

    — answered September 7th 2010 by James K
    permalink
    0 Comments
  • Okay, here is my real code. When you click on one of the rows, the new window opens up but there is no title (As set in the var) and it doesn't link to the new file (Which should be "season1.js" or "season2.js").

    — answered September 7th 2010 by Colton Arabsky
    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.