2013-02-06 79 views
0

嗨我想建立一個簡單的移動應用程序使用鈦工作室和麪臨的問題,從Android模擬器中的表視圖列表項打開新窗口。這是我在我的js文件中使用的代碼。新窗口是不是在Android模擬器使用鈦打開

app.js

var tabGroup = Titanium.UI.createTabGroup(); 

var win = Titanium.UI.createWindow({ 
    backgroundColor: "#FFF" 
}); 
var tab = Titanium.UI.createTab({ 
    icon:'KS_nav_ui.png', 
    title:'REGISTRY', 
    window:win 
}); 

var regItems = [ 
    {title: "List Item One", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true}, 
    {title: "List Item Two", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true}, 
    {title: "List Item Three", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true} 
] 

var regItemList = Titanium.UI.createTableView({ 
    data: regItems 
}); 

regItemList.addEventListener('click', function(e){ 
    var win2 = Titanium.UI.createWindow({ 
     url: "newWin.js", 
     title: e.rowData.title, 
     backgroundColor: "#273691" 
    }); 

     win2.open(); 
// tab.open(win2, {animated: true}); This is also not working 

}); 

win.add(regItemList); 

// open tab group 
tabGroup.open(); 

newWin.js

var newWinCreate = Titanium.UI.currentWindow; 

var labelName = Titanium.UI.createLabel({ 
    title: "First Name", 
    font: {fontSize: 18}, 
    top: 10, 
    left: 20, 
    color: "#fff", 
    textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER 
}); 

newWinCreate .add(labelName); 
+0

是regItemList單擊事件工作?你有沒有在日誌中看到任何錯誤或警告? –

+0

是的,它正在工作,例如,如果我把警報();它顯示了警報窗口。 – Raghav

回答

0

我做了一些修改的代碼,它工作正常現在

app.js

var tabGroup = Titanium.UI.createTabGroup(); 
a 
var win = Titanium.UI.createWindow({ 
    backgroundColor: "#FFF" 
}); 
var tab = Titanium.UI.createTab({ 
    icon:'KS_nav_ui.png', 
    title:'REGISTRY', 
    window:win 
}); 

var regItems = [ 
    {title: "List Item One", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true}, 
    {title: "List Item Two", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true}, 
    {title: "List Item Three", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true} 
] 

var regItemList = Titanium.UI.createTableView({ 
    data: regItems 
}); 

regItemList.addEventListener('click', function(e){ 
    var win2 = Titanium.UI.createWindow({ 
    url: "newWin.js", 
    title: e.rowData.title, 
    backgroundColor: "#273691" 
}); 

    win2.open(); 
// tab.open(win2, {animated: true}); This is also not working 

}); 

win.add(regItemList); 

tabGroup.addTab(tab); 

// open tab group 
tabGroup.open(); 

newWin.js

var newWinCreate = Titanium.UI.currentWindow; 

var labelName = Titanium.UI.createLabel({ 
    text: "First Name", 
    font: {fontSize: 18}, 
    top: 10, 
    left: 20, 
    color: "#fff", 
    textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER 
}); 

newWinCreate.add(labelName); 
0

你犯了一個簡單的錯誤。 您沒有將選項卡添加到tabGroup。 只是將下面的行添加到您的代碼:

tabGroup.addTab(tab); 

就是這樣。希望它會有所幫助。

相關問題