我创建了一个导航窗口 - Titanium.UI.iOS.NavigationWindow
我添加了三个窗口
我打开了所有三个窗口
现在我如何让window3先关闭window1和window 2
var ani =false;
var winRoot = Titanium.UI.createWindow({
backgroundColor: 'red',
title: 'Red Window'
});
var win = Titanium.UI.iOS.createNavigationWindow({
window: winRoot
});
var button = Titanium.UI.createButton({
title: 'Open Blue Window'
});
button.addEventListener('click', function(){
win.openWindow(win1, {animated:ani});
});
winRoot.add(button);
var win1 = Titanium.UI.createWindow({
backgroundColor: 'blue',
title: 'Blue Window'
});
var button1 = Titanium.UI.createButton({
title: 'Open Green Window'
});
button1.addEventListener('click', function(){
win.openWindow(win2, {animated:ani});
});
win1.add(button1);
var win2 = Titanium.UI.createWindow({
backgroundColor: 'green',
title: 'green Window'
});
var button2 = Titanium.UI.createButton({
title: 'Open Yellow Window'
});
button2.addEventListener('click', function(){
win.openWindow(win3, {animated:ani});
});
win2.add(button2);
var win3 = Titanium.UI.createWindow({
backgroundColor: 'yellow',
title: 'yellow Window'
});
var button3 = Titanium.UI.createButton({
title: 'Open Blue Window'
});
button3.addEventListener('click', function(){
win.openWindow(win1, {animated:ani});
});
win3.add(button3);
win.open();
在button3中,如果不关闭黄色和绿色窗口,我将无法返回蓝色窗口
答案 0 :(得分:1)
您无法在NavigationWindow中打开两次相同的窗口。如果你想把它带到前面你必须关闭它而不是再次打开:
以下是您修改的代码。我创建了一个事件监听器,它根据按钮自定义属性target
关闭并打开给定窗口:
var windows = {};
function openWindow() {
win.closeWindow( windows[this.target] );
win.openWindow( windows[this.target] );
}
windows.red = Titanium.UI.createWindow({
backgroundColor: 'red',
title: 'Red Window'
});
var win = Titanium.UI.iOS.createNavigationWindow({
window: windows.red
});
var button = Titanium.UI.createButton({
title: 'Open Blue Window',
target: 'blue'
});
button.addEventListener('click', openWindow);
windows.red.add(button);
windows.blue = Titanium.UI.createWindow({
backgroundColor: 'blue',
title: 'Blue Window'
});
var button1 = Titanium.UI.createButton({
title: 'Open Green Window',
target: 'green'
});
button1.addEventListener('click', openWindow);
windows.blue.add(button1);
windows.green = Titanium.UI.createWindow({
backgroundColor: 'green',
title: 'green Window'
});
var button2 = Titanium.UI.createButton({
title: 'Open Yellow Window',
target: 'yellow'
});
button2.addEventListener('click', openWindow);
windows.green.add(button2);
windows.yellow = Titanium.UI.createWindow({
backgroundColor: 'yellow',
title: 'yellow Window'
});
var button3 = Titanium.UI.createButton({
title: 'Open Blue Window',
target: 'blue',
});
button3.addEventListener('click', openWindow);
windows.yellow.add(button3);
win.open();
另一种方法是创建具有相同参数的新窗口:
var params = {
red: {
window: {
backgroundColor: 'red',
title: 'Red Window',
},
button: {
title: 'Open Blue Window',
target: 'blue'
}
},
blue: {
window: {
backgroundColor: 'blue',
title: 'Blue Window',
},
button: {
title: 'Open Green Window',
target: 'green'
}
},
green: {
window: {
backgroundColor: 'green',
title: 'Green Window',
},
button: {
title: 'Open Yellow Window',
target: 'yellow'
}
},
yellow: {
window: {
backgroundColor: 'yellow',
title: 'Yellow Window',
},
button: {
title: 'Open Red Window',
target: 'red'
}
}
};
function createWindow(color) {
var win = Titanium.UI.createWindow(params[color].window);
var button = Titanium.UI.createButton(params[color].button);
win.add(button);
button.addEventListener('click', function() {
navwin.openWindow( createWindow( this.target ) );
});
return win;
}
var navwin = Titanium.UI.iOS.createNavigationWindow({
window: createWindow('red')
});
navwin.open();
尝试这两个示例并检查哪种行为更适合您。