Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created May 13, 2011 10:27
Show Gist options
  • Save pec1985/970314 to your computer and use it in GitHub Desktop.
Save pec1985/970314 to your computer and use it in GitHub Desktop.
Swipe on a row to add custom elements
var win = Titanium.UI.createWindow({
title:'table',
});
var table = Ti.UI.createTableView({});
win.add(table);
var oldRow = {};
function swipe(a,b,c){
// a = view
// b = selected row
// c = row id
// oldRow = previous selected row
a.addEventListener('swipe', function(e){
if(oldRow.children){
for(var i = 1; i < oldRow.children.length; i++){
oldRow.remove(oldRow.children[i]);
}
};
var button = Ti.UI.createButton({
title:'Button',
right:20,
width:50
});
b.add(button);
oldRow = b;
button.addEventListener('click', function(){
table.deleteRow(c);
oldRow = {};
})
});
}
for(var i = 0; i < 40; i++){
var row = Ti.UI.createTableViewRow({
title:'Row #'+(i+1)
});
var view = Ti.UI.createView({
top:0,
bottom:0,
left:0,
right:0,
rowId:1,
backgroundColor:'transparent'
});
swipe(view,row,i);
row.add(view);
table.appendRow(row);
}
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment