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.
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 theCustomData
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
. -
I'm the author of this tutorial. I don't see any event handling in your code.
-
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}); });
-
The problem is that you are referencing
e.rowData.title
whentitle
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);
-
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").