Button 按钮单击事件在钛中不起作用
我不熟悉Tianium appcelerator编程。我怀疑按钮单击事件在第一个屏幕中是否正常工作,然后我单击该按钮转到第二个屏幕。第二个屏幕由一个按钮组成,当我单击该按钮时,它将导航到第三个屏幕。但按钮单击事件在第二个屏幕中不工作 我在两个屏幕中编写了相同的代码,如下所示: 请告诉我哪里出错了 第一屏:Button 按钮单击事件在钛中不起作用,button,ios6,appcelerator,titanium-mobile,Button,Ios6,Appcelerator,Titanium Mobile,我不熟悉Tianium appcelerator编程。我怀疑按钮单击事件在第一个屏幕中是否正常工作,然后我单击该按钮转到第二个屏幕。第二个屏幕由一个按钮组成,当我单击该按钮时,它将导航到第三个屏幕。但按钮单击事件在第二个屏幕中不工作 我在两个屏幕中编写了相同的代码,如下所示: 请告诉我哪里出错了 第一屏: Ti.include("Files/MainScreen.js"); var win = Titanium.UI.createWindow({ title:'My Window', b
Ti.include("Files/MainScreen.js");
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
win.open();
var itemView = Titanium.UI.createView({
title:'',
backgroundImage:'splash.png',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"Files/MainScreen.js"
});
newWindow.open(win,{animated:true});
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
MainScreen.js:
Ti.include("CustomerScreen.js");
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
var image = Ti.UI.createImageView({
image:'main_screen.png'
});
win.add(image);
win.open();
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
background : "#000",
title : "",
url:"Files/CustomerScreen.js"
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
win.open();
CustomerScreen.js
var win = Titanium.UI.createWindow({
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
win.open();
请尝试以下代码。我已经根据您的代码创建了一个示例应用程序。试试看 app.js
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
var itemView = Titanium.UI.createView({
title:'Splash screen',
backgroundColor:'yellow',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"MainScreen.js",
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
newWindow.open(win,{animated:true});
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
var win = Ti.UI.currentWindow;
win.title = 'My Window';
var image = Ti.UI.createImageView({
backgroundColor:'red'
});
win.add(image);
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
title : "Customer screen",
url:"CustomerScreen.js",
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
var win = Ti.UI.currentWindow;
//Do stuff here
MainScreen.js
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
var itemView = Titanium.UI.createView({
title:'Splash screen',
backgroundColor:'yellow',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"MainScreen.js",
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
newWindow.open(win,{animated:true});
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
var win = Ti.UI.currentWindow;
win.title = 'My Window';
var image = Ti.UI.createImageView({
backgroundColor:'red'
});
win.add(image);
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
title : "Customer screen",
url:"CustomerScreen.js",
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
var win = Ti.UI.currentWindow;
//Do stuff here
CustomerScreen.js
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
var itemView = Titanium.UI.createView({
title:'Splash screen',
backgroundColor:'yellow',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"MainScreen.js",
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
newWindow.open(win,{animated:true});
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
var win = Ti.UI.currentWindow;
win.title = 'My Window';
var image = Ti.UI.createImageView({
backgroundColor:'red'
});
win.add(image);
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
title : "Customer screen",
url:"CustomerScreen.js",
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
var win = Ti.UI.currentWindow;
//Do stuff here
有很多事情你必须注意
Anand,事件未被触发,我通过编写警报消息尝试了使用,但没有使用。没有Anand,我添加了全部代码。你能看到它并告诉我哪里出错了吗。@rani:你为什么试图包含js文件?从url打开新窗口时,将加载页面。同时尝试将代码更改为custbutton.addEventListener('click',function(){var newWindow1=Ti.UI.createWindow({background:#000',title:,url:“Files/CustomerScreen.js”});newWindow1.open(win,{animated:true});});。我不确定它是否会起作用。只需将整个代码打印出来,让我看看。。。。