Persistant rightNavButton disappears from nav when you go back to previous page

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

My app uses a basic navGroup layout to have a persistent top bar with a back button, title, and custom rightNavButton used to popup a recent news window. At the top of every page I've included a header file with the following:

var btnRecentNews = Ti.UI.createButton({
    width: 75,
    height: 30,
    backgroundImage: 'btnRecentNews.png'
});
 
btnRecentNews .addEventListener('click', function(){
    ... do something ...
});
 
Ti.UI.currentWindow.rightNavButton = btnRecentNews;
This works perfectly fine as long as I continue to go forward in the app but as soon as I click the back button to go to a previous page my custom rightNavButton disappears completely. Is this a bug or am I just not understanding how loaded pages are saved in the navGroup hierarchy? Everything else on the pages stays just fine, it's only the rightNavButton that's affected.

I'm developing on iOS 4.3 with Titanium Mobile 1.6.2. This problem occurs in the emulator as well as on the iPhone 4 and iPad. Any help would be greatly appreciated.

4 Answers

So I find a solution:

win.addEventListener('focus', function (e) {
        var t = e.source.rightNavButton;
        e.source.rightNavButton =null;
        e.source.rightNavButton=t;
 
    });
This restores the rightNavButton every time the windows gets focused. Works with a barImage and a label as titleControl. Tested with Titanium SDK 1.8.2.

I think I solved my own problem!

I think I figured this out. It took a long time and a lot of headache but what I've discovered is that you can't use both a custom rightNavBar and window.barImage at the same time. I have no idea why and it might be a bug but when you go back in the navigation hierarchy the rightNavButton drops behind the barImage. Remove that and you should be golden!

Also just to clarify, I'm adding the rightNavButton to every page via a global header instead of passing it through to each window when it's declared. And I tried creating and adding the rightNavButton after setting the barImage but to no avail, you simply can't have both at once for some reason.

— answered 2 years ago by Chris Hoopes
answer permalink
2 Comments
  • Had this problem a year ago and it still exists in Titanium Mobile 1.8.1. Are they ever going to fix this?

    — commented 1 year ago by Victor Rendon

  • Chris, just to clarify, you're using the barImage on your windows, but instead of adding rightNavButton to each window, you just created a single instance of your rightNavButton and added it to your root window globally?

    That makes sense, but how do you manage doing a global "back" button (leftNavButton) in a navigation group? Doesn't a back button need to be tied to a specific window in a navGroup?

    Using a custom barImage is pretty critical for my app's UI, so I'd love to get this working.

    — commented 1 year ago by Clifton Labrum

Had the same problem just now, and your fix fixed it. Thanks. What's strange is that at another place of my application, the button appears with no problems, even though the window and button parameters are the same in both cases. So there seems to be another mysterious factor in work here.

Its not the barImage since all my app has one and it works perfectly fine.I started having this problem when using 1.8.1 sdk. Went back to test in 1.7.5 and works like it used to so I'm assuming it's a bug with 1.8.1. Still can't find a way around it thou.

— answered 1 year ago by natalia caamal
answer permalink
2 Comments
  • Hey guys, something curious is happening, would like to know if the same is happening to you. If you click where the button is supposed to be, the button works - the button IS there somehow invisible. Please let me know if this is happening to you too.

    — commented 1 year ago by natalia caamal

  • Yep, same thing happening with me. However, I only see it when I've chained two windows together that have a rightnav button, then open a third without a button. Going back to #2 loses the button but going back to #1 it shows up again.

    I'm also seeing the same thing that if you click on where it's supposed to be, the button works.

    — commented 1 year ago by Jeff Gordon

Your Answer

Think you can help? Login to answer this question!