Button click event not firing after re-opening window

You must Login before you can answer or comment on any questions.

We're working on a mobile iPad app for IOS 5. The app is set up using navgroups. We have a main page which opens a secondary page when a button is clicked. The secondary page contains buttons for editing text (i.e. the user can type text which will appear on a label and the buttons allow the user to change font styles, size, color, etc... of the typed text). There is also an imageView in the window. Everything in the window functions normally when it is opened the first time. After clicking on the left nav button to go back to the main page and then subsequently re-clicking the button to navigate back to the secondary page, the button event listeners won't respond. The window looks normal but clicking the buttons this time does nothing. We have put Ti.API.info("I'm here") printouts in the button click event listeners to see if they are being called and nothing is printed out in the log. Has anybody come across this problem yet or does anybody have any idea what's going on? My first thought is that the window isn't closing properly but I'm not sure why it would cause a problem like this.

Problem occurs in both ipad simulator and ipad 2 device. No errors are shown. Titanium SDK version: 1.7.3. iPhone SDK version: 4.2.

Thanks for any help

— asked 1 year ago by T.J. Plecha
6 Comments
  • Hi,

    can you share us some sample code that replicates the issue so that we can help you the best.

    — commented 1 year ago by Sattanaathan Ravi

  • Hmmm...I tried to make a simplified version of our code to post on here but I couldn't get it to replicate the problem. I'd rather not post my full code on here and it wouldn't really be practical to ask someone to look through it all. I guess I will continue to debug and update my findings as I go along. Thanks.

    — commented 1 year ago by T.J. Plecha

  • Ok. I have finally figured out what was causing the problem (though I'm still not sure why). The problem was with the zIndex property on the buttons. When I removed the zIndex property, the code started functioning normally. Here is some sample code to illustrate.

    app.js

    //first window in nav group
    var win = Titanium.UI.createWindow({  
        title:'win'
    });
     
    var navGroup = Titanium.UI.iPhone.createNavigationGroup({
        window: win
    });
     
    //second window to open
    var win2 = Titanium.UI.createWindow({  
        title:'win2',
        url: 'win2.js',
        backgroundColor: 'gray'
    });
     
     
    //button to open second window
    var win2Button = Ti.UI.createButton({
        title: 'open win2 button',  
        width: 200,
        height: 60
    });
     
    win.add(win2Button);
     
    var main = Ti.UI.createWindow({orientationModes: [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT]});
    main.add(navGroup);
    main.open();
     
    win2Button.addEventListener('click', function(event){   
    navGroup.open(win2, {animated:true});
    win2.navGroup = navGroup;
    });
    win2.js
    var win = Titanium.UI.currentWindow;
    var navGroup = win.navGroup;
     
    //this is the button that causes problems
    var myButton = Ti.UI.createButton({ 
        width: '20%', 
        height: 60,  
        zIndex: 100,  //this line causes problems. if deleted, code works fine
        title: 'My Button'
    });
     
    win.add(myButton);
     
    //this is only called when the win2 is opened once, not any subsequent openings of win2
    myButton.addEventListener('click', function(e){
        Ti.API.info('im here');
    });
    So to reiterate, when the button in the first window is clicked, win2 opens fine and the button in win2 works properly. Clicking the left nav button to go back to the first window works as it should also. Then clicking the button on the first window again to go back to win2 works properly. However, clicking the button in win2 the second time when the window is reopened will NOT work. Deleting the zIndex property of myButton in win2 solved the problem for me. Not sure if this is a bug or something I'm doing wrong but at least it works now.

    — commented 1 year ago by T.J. Plecha

  • Show 3 more comments

Your Answer

Think you can help? Login to answer this question!