I am developing an iOS app. I got four tabs. How can I change the content of the window when the user clicks a special button or navbar title?
For example if the tab_1 is set to open window_1.js in app.js how can I open window_2.js in tab_1 upon button click? I would prefer not to use views since I would like the content of the window to be in seperate files.
Thankful for all input!
3 Answers
To be sure you can still separate the code into other files. Something like (untested so buyer beware)
window.js
var ns = {}; var showstuff1 = true; Ti.include('winstuff1.js'); Ti.include('winstuff2.js'); var win = Ti.UI.currentWindow; function showstuff() { if(showstuff1) { ns.show_stuff1(win); } else { ns.show_stuff2(win); } } function swap_stuff() { if(showstuff1) { ns.remove_stuff1(win); } else { ns.remove_stuff2(win); } showstuff1 = false; show_stuff(); }winstuff1.js
(function(){ var btn = Ti.UI.createButton({text:'stuff1'}); ns.show_stuff1 = function(win) { win.add(btn); } ns.remove_stuff1 = function(win) { win.remove(btn); } })();winstuff2.js
(function(){ var btn = Ti.UI.createButton({text:'stuff2'}); ns.show_stuff2 = function(win) { win.add(btn); } ns.remove_stuff2 = function(win) { win.remove(btn); } })();Probably bunch of typos but that's the general idea.
Each time your window becomes active it should fire a function.
Try changing the window property of the activetab to whatever window your trying to point to.
tabGroup.addEventListener('focus', function(e) { tabGroup.tabs[e.index].window.url = 'newwindow.js'; });or if that don't work. try assigning the window property to a new window variable.
tabGroup.addEventListener('focus', function(e) { tabGroup.tabs[e.index].window = Titanium.UI.createWindow({url: 'newwindow.js'}); });
Your Answer
Think you can help? Login to answer this question!