[iOS] [Ti 2.0.2] Reload tableview. Bug with tableview.seData([]) ?

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

Hi, I'm trying to reload tableview but it crash after setData([]) (I want clear the tableview to re-populate)

First win focus it's works... from second no... it crash and report: Assertion failure in -[_UITableViewUpdateSupport _computeRowUpdates], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableViewSupport.m:386

If my code is wrong, what's the right method to reload data of tableview ?

tableview2 = Ti.UI.createTableView({            
    backgroundColor: 'transparent',
    style: Ti.UI.iPhone.TableViewStyle.PLAIN,
    separatorStyle: Titanium.UI.iPhone.TableViewSeparatorStyle.NONE,
    top: 2
}); 
 
win.addEventListener('focus', function(){
 
    tableview2.setData([]);
    win.add(function_A());  
    win.add(function_B());
    win.add(function_C());
 
})
 
function function_A(){
 
    var img1 = Ti.UI.createImageView({
        image: '../images/aaa.png',
        top: 8,
        left: 10
    }); 
 
    var img2  = Ti.UI.createImageView({
        image: '../images/bbb.png',
        top: 8,
        left: 120
    }); 
 
    var r = Ti.UI.createTableViewRow({
        hasDetail:false,
        borderColor: 'transparent'
    });
 
    r.add(img1);
    r.add(img2);
    tableview2.appendRow(r);
 
    return tableview2;
}
 
 
function function_B(){
 
    .....
 
    return tableview2;
}
 
function function_C(){
 
     .....
 
    return tableview2;
}
Thank you for help.

Best regard

— asked 1 year ago by Lorenzo Piccinini
2 Comments
  • Hi Lorenzo

    Is it working on earlier version of SDK? Like 1.8.2

    — commented 1 year ago by Jiale He

  • I think I have fixed it by removing "return" in functions.

    tableview2 = Ti.UI.createTableView({            
        backgroundColor: 'transparent',
        style: Ti.UI.iPhone.TableViewStyle.PLAIN,
        separatorStyle: Titanium.UI.iPhone.TableViewSeparatorStyle.NONE,
        top: 2
    }); 
     
    function_A()
    function_B()
    function_C()
    win.add(tableview2);
     
    win.addEventListener('focus', function(){
        tableview2.setData([]);
        function_A()
        function_B()
        function_C()
        win.add(tableview2);    
    })
     
    function function_A(){
     
        var img1 = Ti.UI.createImageView({
            image: '../images/aaa.png',
            top: 8,
            left: 10
        }); 
        var img2  = Ti.UI.createImageView({
            image: '../images/bbb.png',
            top: 8,
            left: 120
        }); 
        var r = Ti.UI.createTableViewRow({
            hasDetail:false,
            borderColor: 'transparent'
        });
     
        r.add(img1);
        r.add(img2);
        tableview2.appendRow(r);
    }
     
     
    function function_B(){
        .....
    }
     
    function function_C(){
         .....
    }

    — commented 1 year ago by Lorenzo Piccinini

2 Answers

Accepted Answer

I had the same error. Every time I reloaded the table, I got this error. My solution was to manage the table data array by my own array. This error was since Titanium SDK 2.0.2.

Previews method of reloading a Table:

mytable.setData([]);
mytable.appendRow(createRow());
mytable.appendRow(createRow());
...
Current reloading
var tableData = [];
tableData.push(createRow());
tableData.push(createRow());
mytable.setData(tableData);
Now it works.

Your Answer

Think you can help? Login to answer this question!