2011-04-26 53 views
0

我有一個包含5個選項卡的選項卡組,其中一個選項卡是「主頁」屏幕。我希望用戶能夠在任何選項卡的窗口中單擊按鈕以返回到主屏幕。如何鏈接到tabGroup中的特定選項卡並使用不同選項卡的窗口中的按鈕?

目前我找到的最接近的方法創建了一個新的窗口,該窗口打破了導航。

var win_home = Titanium.UI.createWindow({ 
url:'home.js' 
}); 

btn_home.addEventListener("click", function() { 
Ti.UI.currentTab.open(win_home,{animated:true}); 
}); 

回答

1

將此代碼添加到您的按鈕事件偵聽器中。

// get the tab group object in the file 
var tabGroup = Titanium.UI.currentTabGroup; 

btn_home.addEventListener("click", function() { 

    // pass the id of your home tab, i used 1 here 
    tabGroup.tabs[1].active = true; 
}); 
+0

爲什麼不只是使用內置方法'tabGroup.setActiveTab(INDEX)'? – bh88 2011-04-26 11:10:41

+0

此外,您的主標籤索引最有可能0不是1,因爲JS數組從0開始 – bh88 2011-04-26 11:13:01

+0

標籤的索引在評論中提及。 – 2011-04-26 11:16:43

相關問題