Skip to content Skip to sidebar Skip to footer

View Is Not Updating From Other Controller Appcelerator Alloy

I hope you will be fine. I am having trouble updating views in Titanium Appcelerator Alloy, I basically want to be able delete previous children from picker and then add new one i

Solution 1:

Since Ok Alert is shown, you are in the good way and the callback function is called successfully. The problem here is that calling removeAllChildren method is not removing rows from your picker. the solution is to iterate over colums and delete rows like this :

Ti.App.addEventListener('db_update', function(){
   alert("OK");
   //get picker columnsvar columns=$.picker.getColumns();
   //Iterate over picker columnsfor (var it=0,length=columns.length;i<length;it++){
        //iterate over column rowsif(columns[it]){
             var len = col.rowCount;
             for(var index=0,collength=columns[it].length;index<collength;index++){
                //remove rows[index] of columns[it]
                columns[it].removeRow(columns[it].rows[index]);
             }
        }
   }
});

By the way Applcelerator's folks said that using global events (Ti.App events) may cause problems in memory managements...

Keep in mind that app-level events are global, which means they remain in context the entire time your app is running (unless you remove them). This also means that any objects they reference will also remain in scope while your app runs. This could prevent those objects from being garbage collected. Appcelerator Documentation.

Another method is to use global functions:

In your first view controller (where picker is defined):

Alloy.Globals.removeAllPickerChildren=function(){
      //do what you want here
};

then in the seconde viewcontroller:

$.btnclick.addEventListener('click', function(){
    if(Alloy.Globals.removeAllPickerChildren)
         Alloy.Globals.removeAllPickerChildren();
});

Post a Comment for "View Is Not Updating From Other Controller Appcelerator Alloy"