Reputation: 2239
I am beginning to work with Ti, and would like to know how is it possible to do the following from the code below:
This is the code that I have so far:
var win = Ti.UI.createWindow({
title: "My Home",
backgroundColor: '#bbb'
});
var b = Ti.UI.createButton({
title:'Button',
style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
win.setToolbar([b]);
var nav = Ti.UI.iPhone.createNavigationGroup({
window:win
});
var root = Ti.UI.createWindow();
root.add(nav);
root.open();
b.addEventListener({
// open a new window with Title as "New Win"
// with a back button, that display the previous title "My Home"
});
Many Thanks.
Upvotes: 2
Views: 3507
Reputation: 4254
You are going with the right approach, only piece is missing is this:
nav.open(myWindow,{animated:true});
here is your full code with the missing code
var win = Ti.UI.createWindow({
title: "My Home",
backgroundColor: '#bbb'
});
var b = Ti.UI.createButton({
title:'Button',
style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
win.setToolbar([b]);
var nav = Ti.UI.iPhone.createNavigationGroup({
window:win
});
var root = Ti.UI.createWindow();
root.add(nav);
root.open();
//This is your new window
var myWindow = Ti.UI.createWindow({
backgroundColor:'#fff',
title:'New Window'
});
// just open this new window with the navigationController you defined
b.addEventListener('click',function(){
nav.open(myWindow,{animated:true});
});
With this code you will see a new window with title "New Window" and with a back button having title as "my Home".
Hope that solve your problem
====================UPDATE:============================================================= To solve your problem you only have to add one line i.e. replace this
var myWindow = Ti.UI.createWindow({
backgroundColor:'#fff',
title:'New Window'
});
by
var myWindow = Ti.UI.createWindow({
backgroundColor:'#fff',
url:'/newWindow.js' // make sure you give the right path
title:'New Window'
});
Upvotes: 3