Bug in tableviewrow with selecting, probably a Titanium SDK bug?

You must Login before you can answer or comment on any questions.

Hi Guys,

So i got my App in the iTunes Store finally but there has been an annoying bug which i can't seem to fix. Its about this app: http://itunes.apple.com/nl/app/psx-sense/id488587133?l=nl&ls=1&mt=8

And the bug is that when u are in the first screen when you start the app, you see a couple of tableviews. When you select one of them but dont actually click it and scroll further, and click another one to actually view. The tableview you first selected opens.

Is there a way to fix this or is this really a SDK-problem?

Code for click is as follows:

tableview.addEventListener('click',function(e) {
    var w = Ti.UI.createWindow({title:'Artikel Bekijken', barColor:'#336699'});
    var wb = Ti.UI.createWebView({url:e.row.url});
    w.add(wb);
King regards,

Roy

— asked 1 year ago by Roy Wijkstra
4 Comments
  • Any luck on resolving this issue? I am having the same issue in 1.8.2 and would love to get it resolved. Thanks

    — commented 1 year ago by Dustin Hume

  • I'm using the very last version of titanium 2.0.2 and have the same issue, is very annoying. I tested it with a very simple app with a selectable table and discovered that as soon as you use any table.addEventListener('click' it starts to fail, but, it only fails when you select it over an object (not the row itself). For example, if I add a label on a row, and I start selecting that row with my finger on the label and then select another row, it selects the row with the label and not the last one.

    I'm thinking about uploading a video and explain it with my iPhone4.

    — commented 12 months ago by Lluis Gerard Lopez

  • Posted the video below as an answer :)

    — commented 12 months ago by Lluis Gerard Lopez

  • Show 1 more comment

5 Answers

I have resolved the issue by setting the touchEnabled attribute to false (touchEnabled:false) for all elements (views, labels, etc) that are added to the tableViewRow.

The issue appears to be caused by the subviews receiving the touch events rather than the tableViewRow and, therefore, not clearing the selected index.

Roy,

I can confirm this behavior in 1.7.5 in one of our production apps as well. Have to say, in testing, I've never "selected" a row then clicked on another. Post it to the JIRA and let me know the id so I can follow it for attention.

— answered 1 year ago by Stephen Feather
answer permalink
2 Comments
  • Hi Stephen,

    My users have been complaining about it and they found it annoying at times on accident selecting for example. I just needed to be sure that this was a problem in the SDK and not something on my own side. Thanks for your reply, i will add it to the JIRA.

    — commented 1 year ago by Roy Wijkstra

  • Roy,

    I get the same results adding the click event to the row instead of to the table.

    — commented 1 year ago by Stephen Feather

Has anyone been able to resolve this problem. I am having the same issue with 1.8.2 and noticed that the KitchenSink app behaves the same way. I would love to get this fixed.

Ok, I posted a video on youtube using an iPhone4 that really explains it all :)

The code used:

var win = Titanium.UI.createWindow({ 
    backgroundColor:'#000'
});
 
// ROW 0
var TableViewRow0 = Ti.UI.createTableViewRow({
    height:'75dp', backgroundColor:'white', selectedBackgroundColor:'blue',num:0
});
 
var LabelVar0 = Ti.UI.createLabel({
    top:'1dp',left: '6dp',textAlign:"left",text:'number 0',color:'black',font:{fontSize:'25dp'}, height:'25dp'
});
TableViewRow0.add(LabelVar0);
 
// ROW 1
var TableViewRow1 = Ti.UI.createTableViewRow({
    height:'75dp', backgroundColor:'white', selectedBackgroundColor:'blue',num:1
});
 
var LabelVar1 = Ti.UI.createLabel({
    top:'1dp',left: '6dp',textAlign:"left",text:'number 1',color:'black',font:{fontSize:'25dp'}, height:'25dp'
});
TableViewRow1.add(LabelVar1);
 
// ROW 2
var TableViewRow2 = Ti.UI.createTableViewRow({
    height:'75dp', backgroundColor:'white', selectedBackgroundColor:'blue',num:2
});
 
var LabelVar2 = Ti.UI.createLabel({
    top:'1dp',left: '6dp',textAlign:"left",text:'number 2',color:'black',font:{fontSize:'25dp'}, height:'25dp'
});
TableViewRow2.add(LabelVar2);
 
// Table
var table = Ti.UI.createTableView({
    data:[TableViewRow0, TableViewRow1,TableViewRow2],
    borderWidth:'0',
    separatorColor:'black'
});
win.add(table);
 
table.addEventListener('click', function(e) {
    Ti.API.info(e.rowData.num); 
 
});
/*
// A listener on the tableview (not in the table) has the same results
// comment the table click listener if you want to test this one
TableViewRow2.addEventListener('click', function (e) {
    Ti.API.info("**************** " + e.index);
});  */
 
win.open();
(I oversimplified this code duplicating a lot, but it's ok to see where is the problem)

Hope that this video and this code can help to resolve this problem on next versions.

Thanks!,

Lluis Gerard

OK! I've found a workaround!!!! :)

Using data var to save each row and re-setting it again when the touchcancel triggers, does the trick:

table.addEventListener('touchcancel', function(e) {
    Ti.API.info('refreshing table data');       
    table.setData(tableData);   
});
The whole code to see it working is here:
var win = Titanium.UI.createWindow({ 
    backgroundColor:'#000'
});
 
// Table
var table = Ti.UI.createTableView({
    borderWidth:'0',
    separatorColor:'black'
});
var tableData = [];
 
// Rows
for (i = 0; i < 10; i++) {
 
    var row = Ti.UI.createTableViewRow({
        height:'75dp', backgroundColor:'white', selectedBackgroundColor:'blue',num:i
    }); 
    var label = Ti.UI.createLabel({
        top:'1dp',left: '6dp',textAlign:"left",text:'label ' + i,color:'black',font:{fontSize:'25dp'}, height:'25dp'
    });
    row.add(label);
    tableData.push(row);
 
}
table.setData(tableData);
 
// Listener that starts the bug
table.addEventListener('click', function(e) {
    Ti.API.info(e.rowData.num);     
});
 
// Workaround to avoid select and cancel bug
table.addEventListener('touchcancel', function(e) {
    Ti.API.info('refreshing table data');       
    table.setData(tableData);   
});
 
win.add(table);
win.open();
This don't solve the real problem, but it works until appcelerator fix the bug :)

I'm very happy cause I'm doing a demonstration shortly and the way my app works had a lot of troubles with this bug. Hope it can help others in the meantime.

Your Answer

Think you can help? Login to answer this question!