Listener not reacting? Help please?

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

I am programming an App on the iPhone, with Titanium Developer 1.2.2. My app.js simply calls an image (splash screen), then on a click will go to the main win:

Titanium.UI.setBackgroundColor('#000');
 
var win = Titanium.UI.createWindow({
    title: 'CSR',
    backgroundColor:'#ffffff'
});
 
var imageView = Titanium.UI.createImageView({
    image:'images/csrmobile_splash.png',
    width: 320,
    height:480
});
 
imageView.addEventListener('click', function(e) {
    var main_win = Ti.UI.createWindow({url:"js/main.js"});
        main_win.open();
});
win.add(imageView);
win.open();
That listener works fine. In main.js, I create two tabs (one for guide, one for about us) then set their links:
var tabGroup = Titanium.UI.createTabGroup();
 
var home_window = Titanium.UI.createWindow({
    title: 'Online Course Guide',
    url: 'home.js'
});
 
var home_tab = Titanium.UI.createTab({  
    icon:'../images/KS_nav_views.png',
    title: 'Guide',
    window:home_window
});
 
var about_win = Titanium.UI.createWindow({  
    url: 'aboutus.js'
});
 
var about_tab = Titanium.UI.createTab({  
    icon:'../images/KS_nav_ui.png',
    title: 'About Us',
    window:about_win
});
 
tabGroup.addTab(home_tab);  
tabGroup.addTab(about_tab);  
tabGroup.setActiveTab(0); 
tabGroup.open({
    transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
});
This rightly passes control to tab(0) and displays my table-view page by going to home.js:
var cur_win = Ti.UI.currentWindow;
var data = [
 
    { title : 'Option-1', hasChild:true, path : 'option1.js', titleImage : '../images/headico-sm.jpg', leftImage: '../images/leftico.jpg', col : '#007c28' },
    { title : 'Option-2', hasChild:true, path : 'option2.js', titleImage : '../images/headico-sm.jpg', leftImage: '../images/leftico.jpg', col : '#007c28' },
    { title : 'Option-3', hasChild:true, path : 'option3.js', titleImage : '../images/headico-sm.jpg', leftImage: '../images/leftico.jpg', col : '#007c28' },
    { title : 'Option-4', hasChild:true, path : 'option4.js', titleImage : '../images/headico-sm.jpg', leftImage: '../images/leftico.jpg', col : '#007c28' },
    { title : 'Option-5', hasChild:true, path : 'option5.js', titleImage : '../images/headico-sm.jpg', leftImage: '../images/leftico.jpg', col : '#007c28' },
    { title : 'Option-6', hasChild:true, path : 'option6.js', titleImage : '../images/headico-sm.jpg', leftImage: '../images/leftico.jpg', col : '#007c28' }
];
 
//Create table for choices and fill with the above data
 
var tableView = Titanium.UI.createTableView ({
    data : data
});
 
//When item is clicked on, create a new window and show it
 
tableView.addEventListener('click', function(e) {
    alert("You clicked?");
    if (e.rowData.path) {
        new_window = Titanium.UI.createWindow({
            url : e.rowData.path,
            title : e.rowData.title,
            titleImage : e.rowData.titleImage,
            barColor : data[e.index].col
        });
        Titanium.UI.currentTab.open(new_window,{animated:true});
    };
});
cur_win.add(tableView);
cur_win.open();
The view displays properly, but tabs or tabled items are not clickable. When I put the alert trap in the listener (as you see) I never get that alert, so it means the listener isn't firing some how.

Can someone please show me the error of my ways?

Thanks!

— asked 2 years ago by Korky Kathman
3 Comments
  • Korky

    Please state your mobile platform, and 3rd-party and Titanium SDK versions, as you should as a matter of course whenever you create a question. Question tags are a good place for this information.

    — commented 2 years ago by Paul Dowsett

  • Sorry Paul, I have amended the question to include the mobile platform (iPhone) and TD version (1.2.2). Not sure about the 3rd party stuff, as I'm not using anything other than javascript. As an editor, I'm using TextMate on a MAC running 0SX Snow Leopard, if that information helps. Thanks!

    — commented 2 years ago by Korky Kathman

  • OK, thanks for this. The 3rd-party SDK version is the iOS version you are targetting. Regarding your question, tabGroups on iOS work quite differently to Android, so this information is useful. Hopefully Aaron's answer will help you resolve the problem.

    — commented 2 years ago by Paul Dowsett

1 Answer

Accepted Answer

I believe you need to add the tabGroup to the window

// main.js
var cur_win = Ti.UI.currentWindow;
var tabGroup = Titanium.UI.createTabGroup();
cur_win.add(tabGroup);

— answered 2 years ago by Aaron Saunders
answer permalink
1 Comment
  • Aaron - thanks, and you got really close and I was able to see it. Actually I don't need to add the createTabGroup(), because it was added up earlier in the function. But adding these statements at the bottom, did the trick.

    var cur_win = Ti.UI.currentWindow;
    cur_win.add(tabGroup);
    Silly mistake I admit...but then I haven't been impressed with the documentation so far... I think we're all learning by Trial and Error! Many thanks, though!

    — commented 2 years ago by Korky Kathman

Your Answer

Think you can help? Login to answer this question!