Navgroups and titleControl

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

Using 1.5.1, with iOS 4.2.

I cannot for the life of me get a button to consistently populate the titleControl of windows as I move through them with the navgroup.

I've tried everything, from passing the button to the new window, to setting it before the window is opened... you can sort of see it when the window changes but then is slides away and disappears.

Does anyone have any experience combining these two elements?

— asked 2 years ago by Adam Campbell
2 Comments
  • can you post a small example of what you are trying to accomplish?

    — commented 2 years ago by Aaron Saunders

  • It's pretty complicated at this point... not sure how to post any code. Can I try to explain the hierarchy? I have a Tabgroup of two tabs/windows: 1. Categories 2. Orders I've made the Categories tab into a Navgroup as well. When you click on a Category within that window it, naturally, takes you to a window for that category. This all works great, but here's the fun part. I have a "Global Browser" button that sits in the titleControl. It triggers a popover that let's you navigate to any category regardless of where you are. The button appears fine the first time, but when you select a new Category to jump to, the navgroup kicks in. It slides to the right to the new window, and doesn't add the button. This is where I'm stuck. What I'd like to do is: a) Not have to stick below that navgroup. b) Be able to carry the button in the titleControl anywhere. I suppose I could ditch the navgroup all together somehow, but I might need some direction there. Thanks!

    — commented 2 years ago by Adam Campbell

1 Answer

Accepted Answer

You need to recreate the titleControl Button on each and every window. I wouldn't try to pass the button from window to window. Rather, just recreate it on each page. To keep things nice and tight, you could put the logic for the button in a separate JS file, and then include that file on every page you want the titleControl to be on.

Something like this:

File: title-control-button.js

(function(){
    Ti.UI.currentWindow.addEventListener('open', function(e){
        var titleButton =  Ti.UI.createButton({
            title:'Press Me',
            style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
        });
 
        titleButton.addEventListener('click', function(){
            // Open new modal window
            var win = Ti.UI.createWindow({url:'new-modal-window.js'});
            win.fooBar = fooBar;
            win.open({modal:true, navBarHidden:false});
        });
 
        Ti.UI.currentWindow.titleControl = titleButton;
    });
}());
And then, on each page you want this button to be on, add this line to the top of the file:
Ti.include('title-control-button.js');
 
var fooBar = 42; // data from window to pass into modal.

— answered 2 years ago by Bart Lewis
answer permalink
4 Comments
  • This looks good.

    My only issue is that there is a bunch of Category data that needs to travel in the popover/modal. Can I store that as well in this way?

    — commented 2 years ago by Adam Campbell

  • Sure. Just before the win.open line, do: win.myData = myVariable;

    — commented 2 years ago by Bart Lewis

  • I'll edit my original answer...

    — commented 2 years ago by Bart Lewis

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!