TableView setData 2nd use crashes on Android (fine on iPhone)

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

I'm using a TableView to display data. The first time I setData on this table it works fine. However, the second time I attempt I call setData (via the addRows function below) the app crashes on the setData statement on Android. The same code works perfectly well on iPhone.

The code is included below. Any ideas?

mytable = Ti.UI.createTableView( { backgroundColor:'transparent', left:0, top:'95dp', backgroundImage: UI.background_image } );
 
 
addRows = function(rows) {
        var data = [];
        for(var i=0; i<rows.length; i++) {
            var table_row = Ti.UI.createTableViewRow({ id: rows[i].id, name:rows[i].name, height: '60dp' });
            var label_view = Ti.UI.createLabel( {
                text: rows[i].name, name:rows[i].name,
                left: UI.edge, color: UI.text_color,
                font: {fontSize:UI.font_size },
                textAlign: 'left'
            });
            table_row.add(label_view);
            data.push(table_row);
        };
        mytable.setData(data);
    };
 
 
empty = function() {
        Ti.API.info('tablepicker.empty: start. mytable='+mytable);
        mytable.setData([]);
    };

3 Answers

Does this help ?

var addRows = function(rows) {
        var data = [];
        for(var i=0; i<rows.length; i++) {
            var table_row = Ti.UI.createTableViewRow({ id: rows[i].id, name:rows[i].name, height: '60dp' });
            var label_view = Ti.UI.createLabel( {
                text: rows[i].name, name:rows[i].name,
                left: UI.edge, color: UI.text_color,
                font: {fontSize:UI.font_size },
                textAlign: 'left'
            });
            table_row.add(label_view);
            data.push(table_row);
        };
    };
 
mytable.setData(addrows(rows));

— answered 12 months ago by Nick Milner
answer permalink
1 Comment
  • Unfortunately no - as soon as I call setData a second time it crashes, even if the data is an empy array (eg. when I call "empty")

    — commented 12 months ago by Parand Darugar

instead of this

empty = function() {
        Ti.API.info('tablepicker.empty: start. mytable='+mytable);
        mytable.setData([]);
    };
try this
empty = function() {
    var mydata =[];
        Ti.API.info('tablepicker.empty: start. mytable='+mytable);
        mytable.data = mydata;
    };

I had a similar issue with setData. After many hours I determined that removing navBarHidden from my windows resolved the issue. If you have that set on your windows it's worth a try to remove it. I used fullscreen: true in place of navBarHidden: true.

Your Answer

Think you can help? Login to answer this question!