Titanium JS: Close all windows under an iOS NavigationWindow and return to the root window

StackOverflow https://stackoverflow.com/questions/23128199

  •  05-07-2023
  •  | 
  •  

Question

In Titanium JS, I'm using the newer NavigationWindow component, and you can traverse several windows down into a navigation tree, creating a series of back buttons as you go.

However, I also have a side revealing menu with a "home" option. I'd like this button to take you back to the root window in the NavigationWindow.

Here is a simple example. Imagine that the new window being created could happen several times and you could be several windows into the navigation tree.

In my view

<Alloy>
    <NavigationWindow id="navWin" class="container">
        <Window title="Window 1">
            <Button onClick="newWindow" title="Go to new window" />
        </Window>
    </NavigationWindow>
</Alloy> 

And in my controller:

function newWindow() {
    var newWin = Ti.UI.createWindow({ title: "Window 2" });
    var goBackBtn = Ti.UI.createButton({ title: "Go to root" });
    newWin.add(goBackBtn);
    goBackBtn.addEventListener("click", function () {
       // goes back to the root window no matter how deep into the navigation tree you are 
    });
    $.navWin.openWindow(newWin); }

$.navWin.open();
Was it helpful?

Solution

Use navAlloy controller for coming to home window

https://github.com/vuinguyen/NavControlTi32

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top