2013-11-27 18 views
0

我是鈦工作室的新手。我試圖做到這一點,當用戶點擊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

嗨,我已經在Android上測試了您的代碼與SDK 3.1.3GA,它適用於我。我看到win1(黑色背景)上的按鈕1和按鈕2,然後我按下一個按鈕,它打開win2(白色背景)。怎麼了?你期望另一種行爲? – kabomi

+0

是的,我處理了這個問題。這裏是問題, win1.add(button1); win1.add(button2); win1.open(); 我刪除了win1.open()它開始工作。當我將win1.open()放在那裏時,我認爲編譯器會看到代碼並開始運行第一個窗口。我不需要這樣。 – arsnlupn

回答

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 
}); 
+0

我處理了這個問題。感謝您的幫助 – arsnlupn

+0

我讀過您的評論,並驚訝於如何可能不使用開放的方法,仍然打開窗口...? –

+0

Mitul Bhalia,我想你誤解了我的評論,實際上發佈了我沒有很好地評論評論。所以我沒有刪除打開的方法,我只是移動它不同的路線。爲了清楚起見,我不能再編寫修改後的代碼。 – arsnlupn