×

HELLO, MY
NAME IS MARTIN
AND THIS IS
MY BLOG

Using Titaniums NavigationWindow in Alloy

Posted on

Since iOS7 was introduced, the days of good old NavigationGroups are over. Being deprecated in Titanium SDK 3.1.3, NavigationGoup will be removed completely in 3.2.0. But what is different?

The NavigationGroup used to sit in a top Window. The NavigationWindow is, as the name suggests, a window itself. Therefore the extra window is not necessary anymore. Consequently, the xml markup looks like this:

<Alloy>
  <NavigationWindow id="mainNavWin" platform="ios"></pre>
    <Require type="view" src="firstWindow"/>
  </NavigationWindow>
</Alloy>

But how do we open another window in our NavigationWindow? With a NavigationWindow, open() and close() will not work anymore. Instead, Appcelerator has introduced two new methods: push() and pop(). So here is how it looks like in our controller: With the official release of Titanim SDK 3.1.3 GA, push & pop have been replaced by openWindow() & close()

var anotherWindow = Alloy.createController('anotherWindow').getView();
$.mainNavWin.openWindow(bookEvent, {animated : true});

If you want to add further windows to your NavigationWindow, I would recommend to set a reference to it at Alloy’s globals:

Alloy.Globals.mainNavWin = $.mainNavWin;

Then you could simply add a new window in a controller by saying:

var anEvenBetterWindow = Alloy.createController('anEvenBetterWindow').getView();
Alloy.Globals.mainNavWin.push(anEvenBetterWindow, {animated : true});

That’s it, simple as that!