Hello,
If you are using Sencha touch 2 beta 3, you might have encounter this issue. If you have a view that you pushing in navigation view you can set title there. This title will be used as a title of navigation bar when this view is activated. See the following code.
config: {
autoDestroy: false,
title: 'Bill'
}
What if you have requirement of setting this dynamically. For example you have a list from which you selected a category.
-Category 1
-Category 2
-Category 3
Based on selected record you will load sub category in next view and you want to display Category 1 as a title in next screen. To load next view you will create it first and push it.
if (!this.menuSubCategory) {
this. menuSubCategory = Ext.create('Application.view.SubCategory');
}
this.getMain().push(this. menuSubCategory);
Here you can set title if you want when you are first creating item. After that you can set it as you already have view. Either you can destroy view every time and create new one else you apply following trick.
This is how next view is loaded. Now if you have set title in config of above view. It will be applied by default. So to dynamically set it you need to do some tweak. First you need to override a base function. See the following code.
Ext.override(Ext.navigation.Bar, {
getNavigationBarProxyProperties: function () {
return {
title: {
left: this.proxy.titleComponent.renderElement.getLeft()
},
backButton: {
left: this.proxy.backButton.renderElement.getLeft(),
width: this.proxy.backButton.renderElement.getWidth()
}
};
}
});
Create an overrides file and add it after sencha touch js file. This is necessary else title width will be less compared to title
Now add the following code after you pushed your view to navigation view.
this.getMain().query('#navBar')[0].titleComponent.setWidth(100);
this.getMain().query('#navBar')[0].titleComponent.setTitle('categoryName');
That's it and you have dynamic title in navigation view. Please note this trick you need to apply if you are using Sencha touch 2 beta 3 version.
If you are using Sencha touch 2 beta 3, you might have encounter this issue. If you have a view that you pushing in navigation view you can set title there. This title will be used as a title of navigation bar when this view is activated. See the following code.
config: {
autoDestroy: false,
title: 'Bill'
}
What if you have requirement of setting this dynamically. For example you have a list from which you selected a category.
-Category 1
-Category 2
-Category 3
Based on selected record you will load sub category in next view and you want to display Category 1 as a title in next screen. To load next view you will create it first and push it.
if (!this.menuSubCategory) {
this. menuSubCategory = Ext.create('Application.view.SubCategory');
}
this.getMain().push(this. menuSubCategory);
Here you can set title if you want when you are first creating item. After that you can set it as you already have view. Either you can destroy view every time and create new one else you apply following trick.
This is how next view is loaded. Now if you have set title in config of above view. It will be applied by default. So to dynamically set it you need to do some tweak. First you need to override a base function. See the following code.
Ext.override(Ext.navigation.Bar, {
getNavigationBarProxyProperties: function () {
return {
title: {
left: this.proxy.titleComponent.renderElement.getLeft()
},
backButton: {
left: this.proxy.backButton.renderElement.getLeft(),
width: this.proxy.backButton.renderElement.getWidth()
}
};
}
});
Create an overrides file and add it after sencha touch js file. This is necessary else title width will be less compared to title
Now add the following code after you pushed your view to navigation view.
this.getMain().query('#navBar')[0].titleComponent.setWidth(100);
this.getMain().query('#navBar')[0].titleComponent.setTitle('categoryName');
That's it and you have dynamic title in navigation view. Please note this trick you need to apply if you are using Sencha touch 2 beta 3 version.

