我是Titanium Studio的新手。我试图在用户点击window1中的任何按钮时执行此操作,它将进入第二个窗口。我的意思是我无法连接到button1和button2以通过第二个窗口。
这是我的示例代码。有人可以帮帮我吗?
Titanium.UI.setBackgroundColor('#000');
var win1 = Ti.UI.createWindow({
layout : 'vertical',
title : 'Welcome to BMI'
});
var button1 = Ti.UI.createButton(
{
title:'Standart',
top : 300,
height: 20,
width: 100
});
button1.addEventListener('click', function(e)
{
win1.close();
win2.open();
});
var button2 = Ti.UI.createButton(
{
title:'Metric',
top : 350,
height: 20,
width: 100
});
button2.addEventListener('click', function(e)
{
win1.close();
win2.open();
});
win1.add(button1);
win1.add(button2);
win1.open();
var win2 = Ti.UI.createWindow({
backgroundColor: 'white',
layout: 'vertical',
title: 'BMI'
});
var label1 = Ti.UI.createLabel({
color: '#900',
font: { fontSize:48 },
shadowColor: '#aaa',
shadowOffset: {x:5, y:5},
text: 'Body Mass Index',
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
top: 30,
width: Ti.UI.SIZE, height: Ti.UI.SIZE
});
var label2 = Ti.UI.createLabel({
color:'blue',
text: 'Welcome to BMI',
textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
top: 30,
width: 300, height: 200
});
win2.add(label1);
win2.add(label2);
答案 0 :(得分:0)
我认为执行此代码不应该遇到问题,但我认为您需要在代码中进行一些修改。
Titanium.UI.setBackgroundColor('#000');
function openNewWin(){
var win2 = Ti.UI.createWindow({
backgroundColor: 'white',
layout: 'vertical',
title: 'BMI'
});
var label1 = Ti.UI.createLabel({
color: '#900',
font: { fontSize:48 },
shadowColor: '#aaa',
shadowOffset: {x:5, y:5},
text: 'Body Mass Index',
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
top: 30,
width: Ti.UI.SIZE, height: Ti.UI.SIZE
});
var label2 = Ti.UI.createLabel({
color:'blue',
text: 'Welcome to BMI',
textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
top: 30,
width: 300, height: 200
});
win2.add(label1);
win2.add(label2);
win2.open({
modal : true
});
}
var win1 = Ti.UI.createWindow({
layout : 'vertical',
title : 'Welcome to BMI'
});
var button1 = Ti.UI.createButton(
{
title:'Standart',
top : 300,
height: 20,
width: 100
});
button1.addEventListener('click', function(e)
{
win1.close();
openNewWin();
});
var button2 = Ti.UI.createButton(
{
title:'Metric',
top : 350,
height: 20,
width: 100
});
button2.addEventListener('click', function(e)
{
win1.close();
openNewWin();
});
win1.add(button1);
win1.add(button2);
win1.open({
modal : true
});