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.
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.
Your Answer
Think you can help? Login to answer this question!