有人知道如何在钛合金中按下标签栏时更改窗口的视图吗? 我已创建标签栏,我不知道如何处理该事件..
这是我的代码:
if (Titanium.Platform.osname === 'iphone'){
var headerDetailTabbedBar = Titanium.UI.iOS.createTabbedBar({
labels:['Header', 'Detail'],
backgroundColor:'#336699',
style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
top:10,
height:25,
width:'85%',
index:0
});
//View Mode
var btnBack = Titanium.UI.createButton({
title:'Back',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
var btnEdit = Titanium.UI.createButton({
title:'Edit',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
//Save Mode
var btnCancel = Titanium.UI.createButton({
title:'Cancel',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
var btnSave = Titanium.UI.createButton({
title:'Save',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
subMenuDisplayEditWindow.setLeftNavButton(btnBack);
subMenuDisplayEditWindow.setRightNavButton(btnEdit);
subMenuDisplayEditWindow.add(headerDetailTabbedBar);
headerDetailTabbedBar.addEventListener('click',function(e){
if(e.index === 0){
//What should i do?
}
else{
//What should i do?
}
});
}
我想要的是在按下选项卡栏时用其他视图更改窗口视图..任何建议?提前谢谢..
答案 0 :(得分:4)
var window = Ti.UI.createWindow();
var headerDetailTabbedBar = Titanium.UI.iOS.createTabbedBar({
labels : ['Header', 'Detail'],
backgroundColor : '#336699',
style : Titanium.UI.iPhone.SystemButtonStyle.BAR,
top : 10,
height : 25,
width : '85%',
index : 0
});
window.add(headerDetailTabbedBar);
var view1 = Ti.UI.createView({
backgroundColor : 'white',
top : 50
});
var view2 = Ti.UI.createView({
backgroundColor : 'red',
top : 50
});
window.add(view2);
window.add(view1);
headerDetailTabbedBar.addEventListener('click', function(e) {
if (e.index == 0) {
view1.visible = true;
view2.visible = false;
} else {
view1.visible = false;
view2.visible = true;
}
});
window.open();
只需更改点击视图的可见性。