Titanium tableview下拉刷新
var lastRow = 10;
//设置默认显示数据
var updating = false;
var loadingRow = Ti.UI.createTableViewRow();
loadingRow.add(Titanium.UI.createLabel({
left : 20,
textAlign : 'center',
text : '数据正在加载,请稍候...', //样式可以自己定义
font : {
fontSize : 14,
fontFamily : 'Helvetica Neue',
fontWeight : 'bold'
}
}));
function beginUpdate() {
updating = true;
//navActInd.show();//此处为title上的nav
tableviewName.appendRow(loadingRow);
setTimeout(endUpdate, 2000);
}
function endUpdate() {
updating = false;
tableviewName.deleteRow(lastRow, {
animationStyle : Titanium.UI.iPhone.RowAnimationStyle.NONE
});
lastRow += 10;
//添加行数
////////重点在此处,其他地方直接用////////function(){}; //此处添加表刷新Event
tableviewName.scrollToIndex(lastRow - 9, {
animated : true,
position : Ti.UI.iPhone.TableViewScrollPosition.BOTTOM
});
//navActInd.hide();
}
var lastDistance = 0;
tableviewName.addEventListener('scroll', function(e) {
var offset = e.contentOffset.y;
var height = e.size.height;
var total = offset + height;
var theEnd = e.contentSize.height;
var distance = theEnd - total;
if(distance < lastDistance) {
var nearEnd = theEnd * .75;
if(!updating && (total >= nearEnd)) {
beginUpdate();
}
}
lastDistance = distance;
});
//设置默认显示数据
var updating = false;
var loadingRow = Ti.UI.createTableViewRow();
loadingRow.add(Titanium.UI.createLabel({
left : 20,
textAlign : 'center',
text : '数据正在加载,请稍候...', //样式可以自己定义
font : {
fontSize : 14,
fontFamily : 'Helvetica Neue',
fontWeight : 'bold'
}
}));
function beginUpdate() {
updating = true;
//navActInd.show();//此处为title上的nav
tableviewName.appendRow(loadingRow);
setTimeout(endUpdate, 2000);
}
function endUpdate() {
updating = false;
tableviewName.deleteRow(lastRow, {
animationStyle : Titanium.UI.iPhone.RowAnimationStyle.NONE
});
lastRow += 10;
//添加行数
////////重点在此处,其他地方直接用////////function(){}; //此处添加表刷新Event
tableviewName.scrollToIndex(lastRow - 9, {
animated : true,
position : Ti.UI.iPhone.TableViewScrollPosition.BOTTOM
});
//navActInd.hide();
}
var lastDistance = 0;
tableviewName.addEventListener('scroll', function(e) {
var offset = e.contentOffset.y;
var height = e.size.height;
var total = offset + height;
var theEnd = e.contentSize.height;
var distance = theEnd - total;
if(distance < lastDistance) {
var nearEnd = theEnd * .75;
if(!updating && (total >= nearEnd)) {
beginUpdate();
}
}
lastDistance = distance;
});
使用方法:修改tableviewName的Name,并在数据处理方法位置做数据获取function
来自:appcelerator-KitchenSink-1.7.2-0
错误或有疑问,请指出,谢谢~