Search code examples
javascriptandroidiostitaniumback

Back button not generating on iOS simulator using Titanium SDK


i am making a project that should show a simple app made in titanium and that should demonstrate how simmilar the apps are in iOS and Android but my problem is i am using PC so i can't realy test things for iPhone from home.

I got a chance to test my app for a few min on a Mac the other day and i noticed that all of my windows are working correctly wich i was quite happy about but the back button is not generating on the iPhone so it is imposible to go back in windows, i had to close the app and restart to check all functions of the app.

So my app starts as a 2 tab app with each tab having a window linked via "url" and each of those windows contain a few buttons that act as a navigation, by pressing a button it directs you further to other windows in different .js files wich may contain links like that on their own like tableviews that onclick go to another window.

app.js

Example for one of the tabs:

var win1 = Titanium.UI.createWindow({  
title:'Informacije',
backgroundColor:'#F4F4F4',
url:'info.js',
layout:'vertical'
});

var tab1 = Titanium.UI.createTab({  
icon:'KS_nav_views.png',
title:'Info',
window:win1
});

Info.js contains 3 buttons each going on click to another window with this code:

    button3.addEventListener('click', function(e){

var newWin3 = Titanium.UI.createWindow({
title:'Kontakt',
url:'kont.js',
layout:'vertical',
backgroundColor:'#4B638D'
});

Titanium.UI.currentTab.open(newWin3,{animation:true});

})

WIndows that open afterwards use "modal" to open since i was not able to open another window in a tab group since there was one there already.

Sorry if this is a simple issue but everything i did till now worked like a charm in android emulator, and i am unable to test on a Mac so i would appreciate if someone could give me a solution.

I have to add that am am new to titanium, javascript and programing in general so im not realy well informed with all solutions , please don't hate on me :)


Solution

  • The automatically generated back button on iOS is a feature of NavigationGroup (now being replaced by NavigationWindow) only. You have to either generate a button which will close the current window manually:

    var win = Ti.UI.createWindow({
        ...
    });
    
    var backButton = Ti.UI.createButton({
       ...
    });
    
    win.setLeftNavButton(backButton);
    
    win.open();
    
    backButton.addEventListener('click', function() {
        win.close();
    });
    

    ( just add the backButton platform dependent by: )

    if(Ti.Platform.name === 'iPhone OS') {
        win.setLeftNavButton(backButton);
    }
    

    or use a NavigationGroup for the iOS Platform only.

    Which rather proves that these platforms are not too similar at all ;)