Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

tableViewRow hasCheck property change kills click color change

Hi all,

I have an event listener listening for a click, which in turn toggles the hasCheck property. This works fine. What doesn't appear to work very consistently is the gradient displayed (the default blue gradient) on click down and undisplayed on click up. When I click and hold the row, I can see the blue gradient, when I release it's gone, just like it's supposed to be, but when I just click (not click and hold) the gradient doesn't appear at all. Does anyone know a solution to this? Help would greatly be appreciated, below is a code snippet:

var win = Titanium.UI.currentWindow;

var categoryArray = ['one','two','three'];
var rowArray = [];

for(var i=0; i<categoryArray.length; i++) {
    var row = Ti.UI.createTableViewRow({className:'aRow',hasCheck:true});
    row.height = 69;
    row.backgroundImage = './images/table_view_row.png';
    var label = Titanium.UI.createLabel({
        color:'#fff',
        font:{fontSize:14},
        text:categoryArray[i],
        top:5,
        left:10
    });
    row.add(label);
    rowArray.push(row);
}


var tableview = Ti.UI.createTableView({
                data:rowArray,
        backgroundColor:'transparent',
        separatorStyle:0
});

tableview.addEventListener('click', function(e)
{
    if(e.rowData.hasCheck) {
        e.rowData.hasCheck = false;    
    }
    else {
        e.rowData.hasCheck = true;
    }
});

win.add(tableview);
— asked October 31st 2010 by Robert Gates
  • hascheck
  • iphone
  • tableviewrow
0 Comments

3 Answers

  • hasCheck is just an indication

    in order to have the default blue color displayed (and staying) you must specify allowsSelection:true in your Ti.UI.createTableView

    var tableview = Ti.UI.createTableView({
                    data:rowArray,
            backgroundColor:'transparent',
            separatorStyle:0,
            allowsSelection:true
    });
    
    — answered October 31st 2010 by Stephane Pelamourgues
    permalink
    0 Comments
  • I'm sorry, maybe I wasn't clear enough, I do not want the blue color to stay, I just want it to indicate the user is touching the row, it needs to be gone on click up. My problem is a short click doesn't display the color at all, just a click and hold. If I don't modify the hasCheck value it works fine.

    — answered October 31st 2010 by Robert Gates
    permalink
    0 Comments
  • I have not really a solution but more a hack … using a setTimeOut, it looks like modifying hasCheck like you do repaint the row so you can't see the blue animation. waiting for the repaint to end solve your issue

    tableview.addEventListener('click', function(e)
    {
      setTimeout(function() {  if(e.rowData.hasCheck) {e.rowData.hasCheck = false;}  else { e.rowData.hasCheck = true;}}, 100);
    
    });
    
    — answered October 31st 2010 by Stephane Pelamourgues
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.