Search code examples
iostitanium-alloyappcelerator-mobile

appcelerator: Pushing new window in to modal window


Hi everyone i have a question regarding modal views in Appcelerator. Currently i have a modal view showing up in the app with a navigation window (see below).

//this is my modal 
<Alloy>
    <NavigationWindow id="win1" platform="ios">
        <Window id="win2" title="Red Window" backgroundColor="red">

        </Window>
    </NavigationWindow>
</Alloy>

//this is the window i want to push in this modal view. 
<Alloy>
    <Window id="win3" title="Blue Window" backgroundColor="blue">
    </Window>
</Alloy>

In my win2.js (which is my parent window and also my modal) i have the following

var window = $.win2;
var navigationwindow = $.win1;

var button = Titanium.UI.createButton({
    title: 'Open Blue Window'
});

button.addEventListener('click', function(){
    navigationwindow.openWindow(win3, {animated:true});
});

But this doesn't do anything. Is it even possible to push windows in an modal window?

I would be very glad if someone here can help me.


Solution

  • openWindow() is the right way to push a new window, but in your win2.js controller the $ variable will only hold references to elements you created in win2.xml and not the view where you created the Navigation Window. In the controller of that view, add a reference like Alloy.Globals.nav = $.win1 (be sure to clean up after closing the Navigation Window) which you then can use in win2.js.