Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Navigation Group Back Button Event

How would I add an event listenter to the Back button of the child window in a Navigation Group?

For example, on clicking to the second window, I change orientation. On clicking the back button, I want to change orientation back.

— asked June 21st 2010 by rob rhyne
  • group
  • mobile
  • navigation
0 Comments

5 Answers

  • The way I did it:

    win.addEventListener('close', function(e)
    {
    alert('you just hit back --ie, this thing closed');
    });
    
    — answered February 14th 2011 by Will Collins
    permalink
    0 Comments
  • Guys, I fix this problem in next way:

    Init code:

    var profileBackButton = Ti.UI.createButton({
        title:'Back'
    });
    profileBackButton.addEventListener('click', function(e){
        SplitViewNav.profileWindow.remove(profileView);
        SplitViewNav.profileWindow.leftNavButton = null;
        SplitViewNav.detailNav.close(SplitViewNav.profileWindow, {animated:true});
        SplitViewNav.detailWindow.leftNavButton = null;
        isProfileWindowOpen = false;
        Ti.API.log('Profile window closed!');
    });
    SplitViewNav.profileWindow = Ti.UI.createWindow({
        backgroundColor:'#fff',
        barColor:'#000',
        title:'Profile',
        leftNavButton:profileBackButton
    });
    

    There is code when I open my window:

            SplitViewNav.profileWindow.leftNavButton = profileBackButton;
            SplitViewNav.detailNav.open(SplitViewNav.profileWindow, {animated:true});
            isProfileWindowOpen = true;
    

    isProfileWindowOpen - I check this var to open/don't open new window (I don't want stack of windows in my navigation)

    — answered June 24th 2010 by Eugenij Sukharenko
    permalink
    0 Comments
  • You could use the window focus event of the parent window to change orientation. This event is fired when the window gets popped off the stack and the parent gains focus - there are examples of the window focus event in the Kitchen Sink for reference.

    — answered June 21st 2010 by Kevin Whinnery
    permalink
    0 Comments
  • Kevin,

    Thanks for your reply!

    The following code is from your post to the developer blog, with three additions being listeners for focus added to all three windows.

    In this code the main listener is fired when the app loads but never again. The first and second window focus listeners are never fired.

    //Here's the first window...
    var first = Ti.UI.createWindow({
      backgroundColor:"#fff",
      title:"My App"
    });
    
    first.addEventListener('focus', function(){
            Titanium.API.log("FIRST WIN FOCUSED");                                     
    });
    
    
    var label = Ti.UI.createLabel({ text: "poke me to open the next window" });
    first.add(label);
    
    //Here's the nav group that will hold them both...
    var navGroup = Ti.UI.iPhone.createNavigationGroup({
      window:first
    });
    
    //Here's a window we want to push onto the stack...
    var second = Ti.UI.createWindow({
      background:"#fff",
      title:"Child Window"
    });
    second.add(Ti.UI.createLabel({text:"Here's the child"}));
    
    second.addEventListener('focus', function(){
        Titanium.API.log("second WIN FOCUSED");                                     
    });
    
    
    //When the label on the first window receives a touch, open the second
    label.addEventListener("click", function(e) {
          navGroup.open(second);
    
    
    });
    
    //This is the main window of the application
    var main = Ti.UI.createWindow();
    main.add(navGroup);
    main.open();
    
    main.addEventListener('focus', function(){
            Titanium.API.log("MAIN WIN FOCUSED");                                     
    });
    

    I've also tried added the second listener after the navGroup open from the label, just in case second didn't want to accept the listener until it was open.

    What am I doing wrong?

    Thanks again!

    (ti mobile, published iphone, sdk 3.1, ti sdk 1.3)

    — answered June 21st 2010 by rob rhyne
    permalink
    0 Comments
  • I am also struggling with capturing focus events as well when using the iphone NavigationGroup control. It appears looking at the KitchenSink example that these events are indeed fired if a TabGroup is used; however, use of the TabGroup proved problematic for different reasons. The example posted is a pretty clear illustration of the problem.

    Is there any event that can be captured when a window is opened by a NavigationGroup?

    — answered June 22nd 2010 by Jeremy Thibeaux
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.