我在尝试向我的按钮添加事件侦听器时遇到问题。这是我的代码中的内容。
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,{animation:true});它甚至不会注册点击...
答案 0 :(得分:2)
首先,您的窗口url
字段名称中不能包含空格,请将Innovations Floors.js
文件重命名为InnovationsFloors.js
。
第二部分是不支持您传递给open()
命令的属性,它应该是animated
而不是animation
,即便如此,您也不应该在此使用此属性时尚,I refer you to the docs on this one.
相反,只需这样做:
Titanium.UI.currentTab.open(InnovationsFloors);
或试试这个:
TabGroup.activeTab.open(InnovationsFloors);
如果这不起作用,则表示您没有在TabGroup上调用open,因此没有当前选项卡。
您也可以随时尝试并打开模态:
InnovationsFloors.open({modal : true});
答案 1 :(得分: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();