Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Tableview click event not firing if table is edited and scrollable is false

$
0
0

I'm having problems with a tableview click event not firing if the table is edited, for example by adding a row, and if scrollable=false.

The following code is a simple example. If the user makes a longpress on a row, then a new row is added. After the row has been added, the first click event (on any row) will not work. A second click will work.

Does anyone have any ideas if I'm doing something wrong, or if there is a workaround?

var win = Ti.UI.createWindow({backgroundColor:'white'});
var table = Ti.UI.createTableView({top:20,scrollable:false});
var tableData = [];
 
// Create some rows
for (var i=0; i<5; i++) {
    var row = Ti.UI.createTableViewRow({title:'Row '+i,myName:'Row '+i});
    tableData.push(row);
}
 
// Add the rows to the table
table.setData(tableData);
 
// Duplicate a row when the user makes a long press, and add the new row to the bottom of the table
table.addEventListener('longpress',function(e){
    var rowData = table.data[0].rows;        
    rowData.splice(rowData.length,0,rowData[e.index]);
    table.setData(rowData);     
});
 
// Test the click event
table.addEventListener('click',function(e) {
    alert(e.source.myName+' clicked');
});
 
 
win.add(table);
win.open();

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>