2013-02-25 87 views
0

我嘗試添加事件監聽器到我的按鈕時遇到問題。這是我的代碼。鈦工作室EventListener的問題

var TabGroup = Titanium.UI.createTabGroup(); 

var Maps = Titanium.UI.createWindow({ 
    backgroundImage:'/images/Background2.jpg' 
}); 
var tab1 = Titanium.UI.createTab({ 
    title: 'Maps', 
    icon: '/KS_nav_ui.png', 
    window: Maps 
}); 
var scrollView = Titanium.UI.createScrollView({ 
    contentWidth:'auto', 
    contentHeight:'auto', 
    top:0, 
    showVerticalScrollIndicator:false, 
    showHorizontalScrollIndicator:false 
}); 
var view = Ti.UI.createView({ 
    height:495, 
    width:300 
}); 
var btnInnovations = Ti.UI.createButton({ 
    height:75, 
    width:Titanium.UI.FILL, 
    backgroundImage:'/images/Innovations.jpg', 
    top:60 
}); 
var btnOaks = Ti.UI.createButton({ 
    height:75, 
    width:Titanium.UI.FILL, 
    backgroundImage:'/images/Oaks Campus.jpg', 
    top:145 
}); 
var btnWHQ = Ti.UI.createButton({ 
    height:75, 
    width:Titanium.UI.FILL, 
    backgroundImage:'/images/WHQ.jpg', 
    top:230 
}); 
var btnRiverport = Ti.UI.createButton({ 
    height:75, 
    width:Titanium.UI.FILL, 
    backgroundImage:'/images/Riverport.jpg', 
    top:315 
}); 
var btnContinuous = Ti.UI.createButton({ 
    height:75, 
    width:Titanium.UI.FILL, 
    backgroundImage:'/images/Continuous.jpg', 
    top:400 
}); 

view.add(btnInnovations); 
view.add(btnOaks); 
view.add(btnWHQ); 
view.add(btnRiverport); 
view.add(btnContinuous); 
scrollView.add(view); 
Maps.add(scrollView); 

TabGroup.addTab(tab1); 
TabGroup.open(); 

btnInnovations.addEventListener('click', function(e){ 
var InnovationsFloors = Titanium.UI.createWindow({ 
title: 'Innovations Floors', 
url:'InnovationsFloors.js' 
}); 

InnovationsFloors.open({modal : true, backgroundImage:'images/Background1.jpg'}); 

我在模擬器中得到的錯誤說不能調用方法打開的不確定,如果我拿出Titanium.UI.currentTab.open(InnovationsFloors,{動畫:真});它甚至不會註冊點擊...

回答

2

首先你不能有空格你的窗口的名稱url字段,請將Innovations Floors.js文件重命名爲InnovationsFloors.js

第二部分是要傳遞到open()命令的屬性不被支持,它應該是animatedanimation,即使是這樣,你不應該以這種方式使用,I refer you to the docs on this one.

,而不是僅僅做到這一點:

​​

或者試試這個:

TabGroup.activeTab.open(InnovationsFloors); 

如果還是不行w ^那麼它意味着你沒有在你的TabGroup上調用open,所以沒有當前標籤。

你也永遠只是試試這個,打開一個模式:

InnovationsFloors.open({modal : true}); 
+0

呀開模做work..but後來就停機,當我真正得到展示形象,我需要在一個新開窗口,以便這些按鈕不會顯示在背景中。我看過一個教程,他使用了Titanium.UI.currentTab.open();工作,但由於某種原因,它不會在我的工作? – quin2195 2013-02-25 19:41:54

+1

如果你的標籤組沒有打開,那麼它不會工作,只是給你的模式窗口一個不透明的背景顏色,這些控件不會顯示在它後面。 – 2013-02-26 04:35:43

+0

但我有我的TabGroup.open();在事件監聽器之前?我能想到的唯一的事情就是使用containsTab.open,因爲它在模板中使用,但這也不起作用? – quin2195 2013-02-28 01:14:14

0

,如果你想打開一個窗口,一個按鈕嘗試這個工作對我來說

// this sets the background color of the master UIView (when there are no windows/tab groups on it) 
Titanium.UI.setBackgroundColor('#000'); 

// create tab group 
var tabGroup = Titanium.UI.createTabGroup(); 


// 
// create base UI tab and root window 
// 
var win1 = Titanium.UI.createWindow({ 
    title:'Tab 1', 
    backgroundColor:'#fff' 
}); 
var tab1 = Titanium.UI.createTab({ 
    icon:'KS_nav_views.png', 
    title:'Tab 1', 
    window:win1 
}); 

var label1 = Titanium.UI.createLabel({ 
    color:'#999', 
    text:'I am Window 1', 
    font:{fontSize:20,fontFamily:'Helvetica Neue'}, 
    textAlign:'center', 
    width:'auto' 
}); 

var button = Titanium.UI.createButton({ 
    title: 'Hello', 
    top: 10, 
    width: 100, 
    height: 50 
}); 

win1.add(button) 
win1.add(label1); 

button.addEventListener('click', function(e){ 
     var win = Titanium.UI.createWindow({ 
      title:'New Window', 
      backgroundColor:'#fff' 
     }); 
     win.open(); 
}); 

tabGroup.addTab(tab1); 

// open tab group 
tabGroup.open();