Help with Pull to Refresh for RSS Feed
Hello, I am looking for some help on adding the 'pull to refresh' code (found here: http://developer.appcelerator.com/blog/2010/05/how-to-create-a-tweetie-like-pull-to-refresh-table.html and in the Kitchen Sink). The code I have for my RSS Feed is pasted at this link: (it's gets a pretty sexy RSS feed with "prettydates" displayed nicely.)
http://pastie.org/1320085
I tried adding this for the Pull to Refresh code:
function formatDate()
{
var date = new Date;
var datestr = date.getMonth()+'/'+date.getDate()+'/'+date.getFullYear();
if (date.getHours()>=12)
{
datestr+=' '+(date.getHours()==12 ? date.getHours() : date.getHours()-12)+':'+date.getMinutes()+' PM';
}
else
{
datestr+=' '+date.getHours()+':'+date.getMinutes()+' AM';
}
return datestr;
}
var border = Ti.UI.createView({
backgroundColor:"#576c89",
height:2,
bottom:0
})
var tableHeader = Ti.UI.createView({
backgroundColor:"#e2e7ed",
width:320,
height:60
});
// fake it til ya make it.. create a 2 pixel
// bottom border
tableHeader.add(border);
var arrow = Ti.UI.createView({
backgroundImage:"../images/whiteArrow.png",
width:23,
height:60,
bottom:10,
left:20
});
var statusLabel = Ti.UI.createLabel({
text:"Pull to reload",
left:55,
width:200,
bottom:30,
height:"auto",
color:"#576c89",
textAlign:"center",
font:{fontSize:13,fontWeight:"bold"},
shadowColor:"#999",
shadowOffset:{x:0,y:1}
});
var lastUpdatedLabel = Ti.UI.createLabel({
text:"Last Updated: "+formatDate(),
left:55,
width:200,
bottom:15,
height:"auto",
color:"#576c89",
textAlign:"center",
font:{fontSize:12},
shadowColor:"#999",
shadowOffset:{x:0,y:1}
});
var actInd = Titanium.UI.createActivityIndicator({
left:20,
bottom:13,
width:30,
height:30
});
tableHeader.add(arrow);
tableHeader.add(statusLabel);
tableHeader.add(lastUpdatedLabel);
tableHeader.add(actInd);
tableView.headerPullView = tableHeader;
var pulling = false;
var reloading = false;
function beginReloading()
{
// just mock out the reload
setTimeout(endReloading,2000);
}
function endReloading()
{
// This is where I get lost
for (var c=0;c<items.length;c++)
{
tableView.appendRow();
// ????
}
// when you're done, just reset
tableView.setContentInsets({top:0},{animated:true});
reloading = false;
lastUpdatedLabel.text = "Last Updated: "+formatDate();
statusLabel.text = "Pull down to refresh...";
actInd.hide();
arrow.show();
}
tableView.addEventListener('scroll',function(e)
{
var offset = e.contentOffset.y;
if (offset <= -65.0 && !pulling)
{
var t = Ti.UI.create2DMatrix();
t = t.rotate(-180);
pulling = true;
arrow.animate({transform:t,duration:180});
statusLabel.text = "Release to refresh...";
}
else if (pulling && offset > -65.0 && offset < 0)
{
pulling = false;
var t = Ti.UI.create2DMatrix();
arrow.animate({transform:t,duration:180});
statusLabel.text = "Pull down to refresh...";
}
});
tableView.addEventListener('scrollEnd',function(e)
{
if (pulling && !reloading && e.contentOffset.y <= -65.0)
{
reloading = true;
pulling = false;
arrow.hide();
actInd.show();
statusLabel.text = "Reloading...";
tableView.setContentInsets({top:60},{animated:true});
arrow.transform=Ti.UI.create2DMatrix();
beginReloading();
}
});
Any suggestions would be greatly appreciated!!
8 Answers
-
This may not help, but I've made a Tweetie-like pull to refresh for Android. It requires set heights, but it works. This should also be able to be used for iPhone, see if you can use it for your project.
-
You might want to look at this
http://developer.appcelerator.com/blog/2010/05/how-to-create-a-tweetie-like-pull-to-refresh-table.html -
Were you ever able to resolve this? I'm pulling in json data and displaying it similar to the twitter example but wanted to use the pull down to refresh. I'm stumped at the same place you were. I'm guessing that my initial data call should be replicated using
function endReloading() { //simulate loading for (var i = widgets; i < widgets; i++) { tableView.setData(rowData); } widgets += 20;
It's not kicking any errors but its not working either.
-
@Forrest - is the tableView's scope correct? It should work.
-
I think setdata is not triggering for (var i = widgets; i < widgets; i++)
function endReloading()
{//simulate loading //for (var c=lastRow;c<lastRow+10;c++) for (var i = widgets; i < widgets; i++) { // tableView.appendRow({title:"Row "+c}); tableView.setData(rowData); }
-
pull to refresh example from kitchen sink is buggy on SDK 1.6.0
see http://developer.appcelerator.com/question/113991/bug-scrollend-event-is-not-returning-negative-contentoffsety-titanium-sdk-160 -
have you ever managed to get it to work?
-
there is a module for android on the market works fine with tableview