The Problem
Using Ti SDK 2.1.x... When clicking on a row, the event fires on a different one. This works fine in 3.0.x
The code
Use this code in app.js
function CheckBox() {
var btn = Ti.UI.createButton({
width : 28,
height : 28,
backgroundImage: 'check_grey.png',
right: 10
});
var checked = false;
btn.addEventListener('btn_click', function(){
if(checked) {
btn.backgroundImage = 'check_grey.png';
} else {
btn.backgroundImage = 'check_blue.png';
}
checked = !checked;
});
return btn;
}
function TableViewRow(n) {
var row = Ti.UI.createTableViewRow({
backgroundColor: '#ccc',
className: 'my_row',
height: 35
});
var checkBox = CheckBox();
row.addEventListener('click', function(){
checkBox.fireEvent('btn_click');
});
row.add(checkBox);
var label = Ti.UI.createLabel({
left: 10,
width: 100,
height: 30,
text: 'Row #' + (n+1),
color: 'black'
});
row.add(label);
return row;
}
var win = Ti.UI.createWindow();
var tableData = [];
for(var i = 0; i < 100; i++) {
tableData.push(TableViewRow(i));
}
var table = Ti.UI.createTableView({
data: tableData
});
win.add(table);
win.open();
To Reproduce
1. Copy that code into app.js
2. Run on device (Galaxy S3 in my case)
3. Click on a row and you'll see the image on the button being changed
4. Scroll down and up
5. Click again and different row from the one clicked will fire the event.
Pull pending against 2_1_X branch https://github.com/appcelerator/titanium_mobile/pull/4055
Verified with: Appcelerator-Studio:3.3.0.201406271159 Sdk:3.3.0.v20140627202512 acs:1.0.14 alloy:1.4.0-rc3 npm:1.3.2 titanium:3.3.0-rc4 titanium-code-processor:1.1.1 xcode:5.1.1 OS:Maverick(10.9.3) Device:iPhone5c(v7.1.1),LG-P970(v4.0.4)