Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with refresh function for page, in Appcelerator

Titanium SDK version: 1.6.1 iPhone SDK version: 4.2

I am using JavaScript.

I am developing an app that is fetching information from an API. In this app, on this page, I got two ways of "refreshing" the content. When the window is focused and when I tap the refresh button.

The problem is every time I do a fresh of the page there is a "copy" of the content under the new content. It is like the app just keeps layering on new copies of the content on top of the others on each fresh.

What am I doing wrong in my code? Is there a way to "clear" the page before each refresh. I can imaging that this issue eats a lot of memory.

You can find my code for the page here: http://pastie.org/1778830

like image 895
Jonathan Clark Avatar asked Mar 19 '26 21:03

Jonathan Clark


1 Answers

this is a common architectural problem, you should separate out the function of creating the table and loading the table's data.

you create the table once when the window is created, and you load the data in the table multiple times. Pseudo code below should give you the basic idea.

var win = Ti.Ui.currentWindow;
(function(){
   var table;

   // create the table
   function initializeWindow() {
   }

   // load the data, and update table
   function loadWindowData() {
   }

   initializeWindow();
   loadWindowData();

   // called whenever you want to update window data.
   Ti.App.addEventListener('app:refreshTable',loadWindowData);
)();
like image 55
Aaron Saunders Avatar answered Mar 21 '26 11:03

Aaron Saunders