This was a question posted in the Appcelerator Q&A and I thought it was an interesting problem so I banged out this solution… It works, could be refactored but I figured I would put it out there since it might be of help for some one.
I really would like to just extend the base NavigationGroup object to provide a easy access to an array of all the windows, a way to pop to the top of the stack and a bunch of other cool things that would be helpful.
Maybe I will add it to my book? Who knows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
var myNavGroup = { navGroup : null, create : function(window) { navGroup = Ti.UI.iPhone.createNavigationGroup( { window : win1, _topWindow: win1 }); // takes the specified window and sets topWindow property // also adds focus event so when it becomes top window // again, the property is set navGroup.pushTopWindow = function(window) { if (window == undefined) { window = navGroup.window; } navGroup._topWindow = window; navGroup._topWindow.addEventListener('focus',function(e){ navGroup._topWindow = e.source; Ti.API.info(window.title + " has focus"); }); }; // when opening a window, set it to the top window navGroup.myOpen = function(window) { navGroup.open(window); navGroup.pushTopWindow(window); }; navGroup.pushTopWindow(); return navGroup; } }; navGroup = myNavGroup.create(win1); |
when you open a window in the navGroup, use the myOpen method
1 |
navGroup.myOpen(detailWindow); |
you can get the top window like this
1 2 |
// probably should make this a nice function, but you get the idea navGroup._topWindow; |
here is a link to another posting on Navigation Groups in Appcelerator that you might find helpful