I'm loading many images from a server, and can't hammer th开发者_JS百科e server with all those requests at once. I want to only load the images once they've scrolled into view on screen, similar to the Facebook iPhone app.
Anybody know how to do this in Titanium?
I think I've seen a clue in the Kitchen Sink / YQL demo: It appears that a table will provide this functionality to the ImageView. Am going to test it...
the table will only load the images for the cells once the row is visible.
Edit: Ignore below, it seems Appcelerator doesn't wait until the images are rendered before requesting the image data. Sounds like a bug.
That sounds right to me. A table (on iOS, at least) will lazy-load its cells, not processing them until they are on the screen. Rather than adding loads of images to a view, if you create table cells instead and insert the images into them they'll be loaded on demand. You can always style the table so it doesn't look like they're in a table, if you don't want that effect.
var table = Ti.UI.createTableView({
separatorColor: '#FFF' // Use this to hide the separator if you don't want it to look like a table
});
var images = []; // This contains your image views
var data = [];
for(var i=0, n=images.length; i<n; i++) {
var cell = Ti.UI.createTableViewRow({
className: 'image' // boosts performance
});
cell.add(images[i]);
data.push(cell);
}
table.data = data;
// Then just add the table to your window
精彩评论