Titanium.UI.currentTab is null?

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

I have copied code straight from the KitchenSink to create a 2 tab setup. My program navigates between the 2 tabs perfectly. The 1st tab is just a label displaying text, the 2nd tab is a TableView listing menu items. It currently has 1 item on it. When you click that item I have this code:

// create table view event listener
    tableview.addEventListener('click', function(e)
    {
        if (e.rowData.test)
        {
            var win = Titanium.UI.createWindow({
                url:e.rowData.test,
                title:e.rowData.title
            });
            Titanium.UI.currentTab.open(win,{animated:true});
        }
    });
This code raises the error: "Result of expression 'Titanium.UI.currentTab' [undefined] is not an object." When you look at "Titanium.UI.currentTab" you get a null value. Why is it null and how can I make sure it is set correctly?

— asked 2 years ago by James Wright
1 Comment
  • In fact, in my app.js before and after I create my tabgroup and call .open() if I log the currentTab like this:

    Titanium.API.info(Titanium.UI.currentTab); // Titanium Log Item
    I get null no matter what.

    — commented 2 years ago by James Wright

3 Answers

Accepted Answer

the work around until it is fixed is to capture the event and set the currentTab yourself

tabGroup.addEventListener('focus', function(e){
    tabGroup._activeTab = e.tab
    tabGroup._activeTabIndex = e.index
    if ( tabGroup._activeTabIndex == -1) return;
    Ti.API.info(tabGroup._activeTabIndex);
    Ti.API.info(tabGroup._activeTab.title);
 
    // create property in Ti namespace
    Ti.API._activeTab = tabGroup._activeTab;
    Ti.API.info(Ti.API._activeTab.title);
 
});

— answered 2 years ago by Aaron Saunders
answer permalink
8 Comments
  • So I have to program my own functionality that mirrors a broken part of the framework? I'm starting to see now why this is free.

    — commented 2 years ago by James Wright

  • On Android the 'focus' event isn't fired on the first open, so the _activeTab will be null until the first tab change.

    — commented 2 years ago by Kristof Gruber

  • Any update on if this is still required to make currentTab functionality actually work?

    — commented 1 year ago by Mark Silverberg

  • Show 5 more comments

I assume you want to get the activeTab.... You need to call activeTab on your TabGroup i.e.;

Ti.API.debug("tabGroup: " + tabGroup.activeTab)
At least thats what I'm using... Please note that there is a problem with tabGroup.activeTab on android in 1.5.1 as it returns undefined. It is however fixed in GIT.

Nils

— answered 2 years ago by Nils Domrose
answer permalink
2 Comments
  • So what do I do if I don't have access to the variable for my tabGroup? I thought the whole point of Titanium.UI.currentTab was that it was accessible everywhere in my app. tabGroup.activeTab works for now, but won't work for what I want later.

    — commented 2 years ago by James Wright

  • There could be only one tabGroup on Android, so I think there is no problem to have a global reference to it.

    — commented 2 years ago by Kristof Gruber

Following up on the comments I manually set the currentTabGroup after the tab was created and seems to work fine for me.

var 
    tabGroup = Titanium.UI.createTabGroup();    
    Titanium.UI.currentTabGroup = tabGroup;  // ** Set reference manually

— answered 1 year ago by Javier Vega
answer permalink
3 Comments
  • I cannot believe that this is still broken (in 1.8.2)... Seems like such basic and important functionality, how can they still not have fixed it over a year later??

    — commented 1 year ago by Brendten Eickstaedt

  • This is a really simple (and smart) workaround. Thanks for sharing.

    — commented 1 year ago by Demostenes Garcia

  • how...? can u please give some more hints on this?

    — commented 12 months ago by George Georgiou

Your Answer

Think you can help? Login to answer this question!