jl.
jl.

Reputation: 2239

Titanium Appcelerator Opens new Window and Dynamic Back button of Previous Title

I am beginning to work with Ti, and would like to know how is it possible to do the following from the code below:

  1. Open a new window/view with title as "New Win"
  2. Display a back button with title "My Home" (of the previous page)

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

Answers (1)

Ajeet Pratap Maurya
Ajeet Pratap Maurya

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

Related Questions