开发者

Titanium Not Loading all HTTPClient XML Requests

I have an application that has 5 windows, and when clicking on the tabs above them passes the window the URL of the RSS to load. It's maddening, and it's about to make me jump ship from Appcelerator to PhoneGap.

This is a last ditch effort before jumping ship..........please tell me I'm doing something silly. It works fine if a bit sluggish on the emulator, but on my Dell Str开发者_StackOverflow中文版eak 5 it's maddeningly inconsistent. Sometimes the XML renders (it always returns with a 4 readystate), somethings it just hangs with the activity indicator spinning. If I rebuild without the activity indicator many times just nothing appears in the windows. No errors to speak of that I can see.

HEre is the offending code. Please tell me I'm doing something horribly wrong to make me happy.

data = [];

//load RSS Feed
Ti.API.info('>>>> loading RSS feed '+url);

//Show Loading Animation
navActInd.show();

var xhr = Ti.Network.createHTTPClient();
xhr.timeout = 10000;
xhr.open('GET', url);

xhr.onload  = function()
 {
     var xml1 = xhr.responseXML;
     var items = xml1.documentElement.getElementsByTagName("item");

//Loop Through XML and Build Rows
     for (var i = 0; i < items.length; i++) {
         this_post_title = items.item(i).getElementsByTagName("title").item(0).text;
         this_post_merchant = items.item(i).getElementsByTagName("category").item(0).text;
         post_cid = items.item(i).getElementsByTagName("source").item(0).text;
         var row = Ti.UI.createTableViewRow();
         var post_title = Ti.UI.createLabel({text: this_post_title});
         row.add(post_title);
         row.thisSource = post_cid;
         row.thisMerchant = this_post_merchant;
         data.push(row);
     }
     navActInd.hide();

     var tv = Titanium.UI.createTableView({
         data: data,
         top: 0,
         width: 'auto',
         height: 'auto'
 });

//Add Table to Window
 window.add(tv);
 navActInd.hide();


first, you shouldn't hide the navActInd twice. you also should add an onerror function to print the status code.

without taking a look at your xml file it's hard to form an opinion.

i understand your frustration about titanium. there are a lot frustration things about it since it's quite complicated to build such a framework. i build a really comprehensive app with titanium and have had a lot of such moments but nether the less i found a solution for all problems;)


I have seen similar issues when the xml is not what I have expected, you should put a try catch block around your xmlparsing block and see if an error is thrown

you should add an onError handler to you code.

from a complexity perspective, you do not need a label to set the title of the row; these lines can be edited

 var row = Ti.UI.createTableViewRow();
 var post_title = Ti.UI.createLabel({text: this_post_title});
 row.add(post_title);

with this line, also use rowClassName whenever possible

var row = Ti.UI.createTableViewRow({title: this_post_title, className:'@row'});
row.add(post_title);

I would also suggest you take a look at the kitchen Sink demo for a complete example. https://github.com/appcelerator/KitchenSink/tree/master/KitchenSink

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜