您好我正在尝试使用Titanium Studio和Facing问题构建一个简单的移动应用程序,以从Android模拟器中的表视图列表项打开新窗口。这是我在js文件中使用的代码。
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 :(得分: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);
答案 1 :(得分:0)
你犯了一个简单的错误。 您没有将标签添加到tabGroup。 只需在代码中添加以下行:
tabGroup.addTab(tab);
就是这样。希望它会有所帮助。