how would you have a new window show or pop open when you hit a nav bar button at the top? As of right now, when I fire the application i want the main screen to show my selections for the app. then from there if a button at the top in the nav bar is pressed, i would like it to pull up a new screen of a list of books. When i hit the button as of right now, i don't get a new screen at all, i get the screen from the app.js. not like i want anything on the screen to work, i just would like a new screen to show instead of the screen from the app.js file.
Here is my app.js file.
var win = Titanium.UI.createWindow({ // backgroundColor : 'white' }); var tb1 = Titanium.UI.createTabbedBar({ labels : ['Sports', 'Map', 'Books', 'Contact'], backgroundColor : '#336699', top : 0, style : Titanium.UI.iPhone.SystemButtonStyle.BAR, height : 40, width : '100%', index : 1, }); win.add(tb1); var newWin = Ti.UI.createWindow({ url : 'book.js' }); tb1.addEventListener('click', function(e) { if(e.index == 0) { var newWin = Ti.UI.createWindow({ url : 'book.js', top : 41 }); newWin.open(); } if(e.index == 1) { var newWin = Ti.UI.createWindow({ url : 'info.js', top : 41 }); newWin.open(); } if(e.index == 2) { var newWin = Ti.UI.createWindow({ url : 'map.js', top : 41 }); newWin.open(); } if(e.index == 3) { var newWin = Ti.UI.createWindow({ url : 'galary.js', top : 41 }); newWin.open(); } }) win.open(); //var win = Titanium.UI.createWindow({ // title:"title", // backgroundColor:"#FFFFFF", //}) //label var label = Titanium.UI.createLabel({ backgroundImage: "images/image.png", top: "10%", width: "100%", height: "12%", textalign: "center", }) // new button var openWebpagenotification = Titanium.UI.createButton({ title:"Notifications", backgroundImage: "images/notificationbutton.png", width:"100%", height:"12%", top:"20%", id: "Notifications", url:"http://www.google/", color: '#000000' }); openWebpagenotification.addEventListener("click", function(e){ // Create a window and add a webview to it that opens your url: var webviewWindow = Titanium.UI.createWindow({title: 'Notifications', fullscreen: false}); var myWebView = Ti.UI.createWebView({url:e.source.url}); webviewWindow.add(myWebView); // Will need a button to close the new window: var closeButton = Titanium.UI.createButton({title:'Close', style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN}); webviewWindow.setLeftNavButton(closeButton); closeButton.addEventListener('click',function(evt){ webviewWindow.close(); }); webviewWindow.open({modal:true}); webviewWindow.open(); // Open your new window }) win.add(label); win.add(openWebpagenotification); win.open();'
now here is the book.js file - this is where i would like a plain screen to show a listing of books. BOOK.js
//////////
function tibook() { var BookWindow = require('book'); var BookWindow = new BookWindow(); bookWindow.open(); var tb1 = Titanium.UI.createTabbedBar({ labels : ['Sports', 'Map', 'Books', 'Contact'], backgroundColor : '#336699', top : 0, style : Titanium.UI.iPhone.SystemButtonStyle.BAR, height : 40, width : '100%', index : 1, }); win.add(tb1); var newWin = Ti.UI.createWindow({ url : 'book.js' }); tb1.addEventListener('click', function(e) { if(e.index == 0) { var newWin = Ti.UI.createWindow({ url : 'book.js', top : 41 }); newWin.open(); } if(e.index == 1) { var newWin = Ti.UI.createWindow({ url : 'geo.js', top : 41 }); newWin.open(); } if(e.index == 2) { var newWin = Ti.UI.createWindow({ url : 'map.js', top : 41 }); newWin.open(); } if(e.index == 3) { var newWin = Ti.UI.createWindow({ url : 'galary.js', top : 41 }); newWin.open(); } }) win.open(); return self; };////////
Thanks for your thoughts and expertise. -paul
1 Answer
You're using a mix of multiple context and commonjs coding here that is just bound to get your wires crossed. When you open a window with a url property, you are creating that window inside a new context. Then inside that new context, it looks like you are suddenly trying to format your code commonjs style. Instead, in your app.js file, you should just require the book as you do in the second file and make that your newWin. Then you can open newWin inside the current context and maybe even reuse the tabbedBar instead of writing all that code again. Code like that should remain DRY (dont repeat yourself).
Your Answer
Think you can help? Login to answer this question!