2013-02-25 89 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();