Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-765] Table View crash on second load

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:54:10.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.3.0
ComponentsiOS
Labelsn/a
ReporterNolan Wright
AssigneeBlain Hamon
Created2011-04-15T02:35:53.000+0000
Updated2011-04-17T01:54:10.000+0000

Description

after initial load, click button to load next set of data. table view crashes

from premium ticket:

http://helpdesk.appcelerator.net/tickets/1847">http://helpdesk.appcelerator.net/tickets/1847

here's the code:

//Variable storing when the platform is android var android = (Ti.Platform.name == "android");

//BG Color to White //Titanium.UI.setBackgroundColor(android?#181818;

//Create 5 individual windows var win1 = Ti.UI.createWindow();

//Create the table view and set the data var tableview = Titanium.UI.createTableView({top:50});
win1.add(tableview);

//Set data counter to keep track of getData calls var dataCount = 0;
var epicFail = false;
//Make client var xhr = Ti.Network.createHTTPClient();

//This function loads the game data function getData(window, platform) {

//Data failure
xhr.onerror = function (e) { 
    if (!epicFail) { 
        alert("A Net Load failed! Best to check your connection and reload app later!"); 
    } 
    epicFail = true; 
};
//Upon data load
xhr.onload = function( ) {
    //Create clean data array
    var data = [];        
    //Get the JSON out
    var resp = eval("(" + this.responseText + ")");

    //Set img width, if DS, make it bigger
    var imgWidth = 50;
    if (platform == "Nintendo%20DS") {
        imgWidth = 75;
    }

    Ti.API.info('PRODUCT COUNT = ' + resp.products.length);

    //Loop through and create rows for every product pulled
    for (var i=0;i < resp.products.length;i++) {
        var row = Ti.UI.createTableViewRow({
            height:70
            //backgroundColor:"white"
        });
        //Get the game name
        var gamename = resp.products[i].name;
        //Replace unwanted data in name
        gamename = gamename.replace("- " + resp.products[i].platform,"");
        gamename = gamename.replace(/&#37;/g,"&");
        gamename = gamename.replace(/&#252;/g,"ü");
        gamename = gamename.replace(/&#233;/g,"é");
        gamename = gamename.replace(/&#33;/g,"©");

        //Create an image for the cell using the thumbnail image

        var img = Ti.UI.createImageView({
            url:resp.products[i].thumbnailImage,
            left:5,width:50,height:67
        });
        //Create a label for the cell using the game name
        var lbl = Ti.UI.createLabel({
            text:gamename,
            top:5,left:imgWidth + 10,
            textAlign:"left",
            font:{fontWeight:"bold",fontSize:12} 
        });
        //Add the label and image to the row          
        row.add(lbl);
        row.add(img);
        Ti.API.info('IMAGE ' + img + ' url ' + img.url + ' i ' + i);

        data[i] = row;
    }
  tableview.setData(data);

};//End onload
xhr.open("GET","http://api.remix.bestbuy.com/v1/products(type=game&;platform=" + platform +")?sort=salesRankShortTerm&format=json&apiKey=sexdfjckv6be3gq49rpt4jby");
xhr.send();

}

//Get the desired data getData(win1,"Xbox%20360");

btn1 = Ti.UI.createButton({

title:"Next platform",
width:120,height:40,top:0

});

btn1.addEventListener("click",function(e) {

//getData(win1, "Nintendo%20DS");
getData(win1, "Xbox");

});

win1.add(btn1);

win1.open();

Comments

  1. kosso 2011-04-15

    I've been having the same issue since yesterday's 'trying to speed up tableviews' commit.

  2. Jeff Haynie 2011-04-15

    (from [9fda09a034a68971fc1d249500663703afc3bba6]) Closes #765: New proxy needed to be retained (may be freed twice). Checking with instruments confirms no memory leak. http://github.com/appcelerator/titanium_mobile/commit/9fda09a034a68971fc1d249500663703afc3bba6"> http://github.com/appcelerator/titanium_mobile/commit/9fda09a034a68...

JSON Source