Search code examples
iostitanium

Keep TableViewRow selected in Appcelerator Titanium


I'm developing a simple product catalog in Titanium and I have a TableView with the list of products and a product detail view to view the selected product. What I want to do is have the selected product visibly selected in the TableView.

Titanium defaults to deselecting rows with animation so the selection color fades out whenever a row is selected.

This is how my app looks like now: This is how my app looks like now

This is how I want it to look: This is how I want it to look

Any ideas?


Solution

  • Give this a try:

    // Create table view data object
    var data = [
        {title:'Row 1', hasChild:true, color:'red', selectedColor:'#fff'},
        {title:'Row 2', hasDetail:true, color:'green', selectedColor:'#fff'},
        {title:'Row 3', hasCheck:true, color:'blue', selectedColor:'#fff'},
        {title:'Row 4', color:'orange', selectedColor:'#fff'}
    ];
    
    // Create table view and set allowSelection to true
    var tableview = Titanium.UI.createTableView({
        data:data,
        allowsSelection:true  // This should do the trick
    });
    
    // Select the 4th row
    tableview.selectRow(3);
    
    // Add table view to the current window
    Titanium.UI.currentWindow.add(tableview);