I have a class called SettingsBar that extends TitleBar in Sencha Touch 2.3. This SettingsBar I'm using has several buttons on it. When you click the Settings button then the bar is added to the panel and it shows up just fine.
You can click the buttons on the SettingsBar and different things will happen in the app. I have it setup so that you can make the SettingsBar disappear if you click the Settings button again. So the Settings button adds and removes the SettingsBar.
When the SettingsBar is added, and you click some of the buttons, then the SettingsBar is removed, the state of the SettingsBar isn't saved. The buttons go back to their original text (their text changes when you click them) and the event handling for them no longer works. You just click them and nothing happens.
Here's my code that adds and removes the SettingsBar:
settingsTap: function(){
if(settingsToolbar.added){
Ext.getCmp('mainview').removeAt(2);
console.log('added: '+settingsToolbar.added);
}else{
Ext.getCmp('mainview').add(settingsToolbar);
console.log('added: '+settingsToolbar.added);
}
settingsToolbar.added = !settingsToolbar.added;
}
The event handling is being done in my controller. Why would the buttons be reset and event handling on them removed when the SettingsBar is removed from the panel?
This is troublesome and has been asked for several times.
The safest way which even works when you destroy the component completely when removing it (you should always do, it reclaims a lot of memory), is to declare the event handlers in the
initializefunction of that component, or its parent component, wherever you think suitable, for example:This is an example for
itemtapevent on aExt.List. Let's adapt it to your case.