[TIMOB-765] Table View crash on second load
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:54:10.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.3.0 |
Components | iOS |
Labels | n/a |
Reporter | Nolan Wright |
Assignee | Blain Hamon |
Created | 2011-04-15T02:35:53.000+0000 |
Updated | 2011-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(/%/g,"&");
gamename = gamename.replace(/ü/g,"ü");
gamename = gamename.replace(/é/g,"é");
gamename = gamename.replace(/!/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();
I've been having the same issue since yesterday's 'trying to speed up tableviews' commit.
(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...