0

タブ付きバーがチタンで押されたときにウィンドウのビューを変更する方法を知っている人はいますか? タブ付きバーを作成しましたが、そのイベントの処理方法がわかりません..

ここに私のコードがあります:

    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?
            }
        });
    }

私が望むのは、タブ付きバーが押されたときにウィンドウのビューを他のビューに変更することだけです..何か提案はありますか?? 前もって感謝します..

4

1 に答える 1

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();

クリック時にビューの可視性を変更するだけです。

于 2012-11-30T07:30:17.380 に答える