Adding Images to RSS Feed
I'm trying to pull the images from my RSS feed into my app. I'm getting an error in the console that says:
[ERROR] invalid image type. expected either TiBlob or TiFile, was: TiUIImageViewProxy in -[TiUIImageView setImage_:] (TiUIImageView.m:618)
Here's the code I'm using:
// create table view data object
var data = [];
var xhr = Ti.Network.createHTTPClient();
xhr.open("GET","http://www.golfwebdesign.com/feed/rss/");
xhr.onload = function()
{
try
{
var doc = this.responseXML.documentElement;
var items = doc.getElementsByTagName("item");
var x = 0;
var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue;
for (var c=0;c<items.length;c++)
{
var item = items.item(c);
var title = item.getElementsByTagName("title").item(0).text;
var row = Ti.UI.createTableViewRow({height:70});
var item_image = Ti.UI.createImageView({
image:item_image,
left:3,
top:2,
width:50,
height:34
});
var label = Ti.UI.createLabel({
text:title,
left:72,
top:5,
bottom:5,
right:5
});
row.add(item_image);
row.add(label);
data[x++] = row;
row.url = item.getElementsByTagName("link").item(0).text;
}
var tableview = Titanium.UI.createTableView({data:data});
Titanium.UI.currentWindow.add(tableview);
tableview.addEventListener('click',function(e)
{
var w = Ti.UI.createWindow({title:doctitle});
var wb = Ti.UI.createWebView({url:e.row.url});
w.add(wb);
var b = Titanium.UI.createButton({
title:'Close',
style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN
});
w.setLeftNavButton(b);
b.addEventListener('click',function()
{
w.close();
});
w.open({modal:true});
});
}
catch(E)
{
alert(E);
}
};
xhr.send();
1 Answer
-
There are two things wrong in this code.
The first is you are assigning item_image to the image property but it has not yet been defined. It would seem you would want to extract it from the RSS feed but have not done so.
The second issue is you are then using the same variable name (item_image) to store the ImageView. This can be problematic if you store the URL to the image in item_image and then overwrite the contents with an ImageView.
var item_image = Ti.UI.createImageView({ image:item_image, left:3, top:2, width:50, height:34 });