Hi guys,
I'm running into a strange problem developing a mobile application. I'm currently working and testing on the iPhone simulator. I'm running Titanium SDK 3.1.1.GA on Mac OS Mountain Lion and building with iOS SDK 6.1.
I'm trying to parse an RSS feed and send the data around elsewhere in the application. I have a Network.js module that creates an XHR object and parses XML. I want to use the parsed items in a TableView UI element in another CommonJS module.
Now, when I create an empty data array and push the parsed items as dictionary data (generating a default TableViewRow in the TableView), the TableView receives and renders the data accordingly.
However, I want to use custom TableViewRows. So, for each item I create a custom TableViewRow. Then I push the row in the data array. But, for some reason this doesn't work. The TableView UI element receives an event but with a (seemingly) empty data array.
So in sum, when I fill the data array with custom TableViewRows the TableView object doesn't display anything. If I push items as a dictionary in the data array then the TableViewRow renders the data fine.
I've seen other code / tutorials / examples where Ti.UI.TableViewRow objects can safely passed to the data array of a TableView. So, am I doing something wrong in sending the data via Ti.App.fireEvent?
Any clues on how to troubleshoot this issue is much appreciated!
Below I pasted the relevant code.
Network.js
xhr.onload = function() { Ti.API.info("Fetching RSS data"); if (this.status == 200) { Ti.API.info("Succesfully requested page.") var doc = this.responseXML.documentElement; var items = doc.getElementsByTagName("item"); var data = []; Ti.API.info(data); for (var i=0; i < items.length; i++){ var raw_uri = items.item(i).getElementsByTagName("description").item(0).text; var begin = raw_uri.indexOf("<img src="); var end = raw_uri.indexOf("/>"); var uri = raw_uri.substring(begin+10,end-1); var title = items.item(i).getElementsByTagName("title").item(0).text; var row = new Row(title, uri); //data.push(row); //<-- Pushing the row doesn't work data.push({ title: items.item(i).getElementsByTagName("title").item(0).text, hasChild: true, url: uri, }); //Pushing data like this does work }; Ti.App.fireEvent("Network:update", {'data': data}); Ti.App.fireEvent("Loader:stop"); } else { Ti.API.info("There was an error fetching the page"); Ti.API.info("Status: ", this.status); } };TableView.js
var TableView = function() { var row = new Row("test", "http://www.blalbla.com"); // This works fine var data = []; data.push(row); var self = Ti.UI.createTableView({ data: data, }); Ti.App.addEventListener("Network:update", function(e){ alert(e); self.setData(e.data); Ti.API.info("Network updated"); }); return self; };