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