0

您好我正在尝试使用 Titanium Studio 构建一个简单的移动应用程序并面临问题,以从 Android 模拟器中的表视图列表项打开新窗口。这是我在 js 文件中使用的代码。

应用程序.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();

新的Win.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);
4

2 回答 2

0

你犯了一个简单的错误。您没有将选项卡添加到 tabGroup。只需将以下行添加到您的代码中:

tabGroup.addTab(tab);

而已。希望它会有所帮助。

于 2013-02-15T06:12:34.787 回答
0

我对代码进行了一些更改,现在工作正常

应用程序.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();

新的Win.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);
于 2013-02-09T15:35:56.663 回答