How to refresh view when tab icon is tapped on iOS

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

Hi guys,

Hopefully a quick one here.

Using iOS and the latest Titanium SDK I have a 5 tab app.

I'm at the last couple of bits required before submission to Apple.

The client has requested that when you tap any of the tab bar icons at the bottom of the app, the view will always revert back to the start of the user journey.

So, say the App has a 'Home' tab bar item, and the user taps it a few times and cycles their way through lots of window views, they then have to press back in the top left many time in order to get back to the main screen.

What they want to happen, is for the user to simply tap the tabbar and for the original starting point view to be shown.

How can I do this?

Simon

— asked 12 months ago by Simon Hume
0 Comments

3 Answers

By tab bar icons, do you mean the tabs in a tab group? If so, assuming each child window is being opened inside the current tab with something like tabGroup.activeTab.open(win), then this should happen automatically.

— answered 12 months ago by Adam Paxton
answer permalink
4 Comments
  • Hi Adam. Yes, tabs in a tab group, sorry! Been a long day. I was thinking it should happen automatically. I may have to check my code and see if i've got something up in there.

    — commented 12 months ago by Simon Hume

  • Adam, this is how i'm opening a window, is this not the right way?

    Ti.UI.currentTab.open(detailWindow,{animated:true});

    — commented 12 months ago by Simon Hume

  • Ti.UI.currentTab has been known to have some problems. Not sure if it is the issue in this case, but I would try switching to using activeTab and seeing if that helps. Depending on how your app is structured, you may need to put your tabgroup inside your global namespace variable so it can be referenced from all windows, or possibly start passing it to the windows.

    Another option is to just add the parent window's tab as an attrribute of the window, so it may be referenced by other child windows. This is how the TabGroup template is doing it, as you can see here iwith containingTab.

    — commented 12 months ago by Adam Paxton

  • Show 1 more comment

I'm pretty sure a double-tap on the tab will do this.

If not, you need to keep a track of an array/stack of the windows you have opened, so that when the tab is clicked (with a click eventListener) you can then loop through them and close them and get back 'home'.

— answered 12 months ago by Kosso .
answer permalink
1 Comment
  • Currently opening a window like this on a click event

    Ti.UI.currentTab.open(detailWindow,{animated:true});
    Is that the right way to do it?

    — commented 12 months ago by Simon Hume

I think I've finally found the part in customTabBar.js that is causing the issue. Can anyone shed any light on what to add inside this function to make the native function work as it should?

You can see the TODO item listed, which is where it needs to live.

Here is the full script on GitHub

var assignClick = function(tabItem) {
        tabItem.addEventListener('click', function(e) {
            // Just fetching the 'i' variable from the loop
            var pos = e.source.pos;
 
            if (tabCurrent == pos) {
                // TODO
                // Change back to root window, like the native tab action.
                return false;
            }       
 
            // Switch to the tab associated with the image pressed
            settings.tabBar.tabs[pos].active = true;
            tabCurrent = pos;
 
 
            // Reset all the tab images
            resetTabs();
 
            // Set the current tab as selected
            tabBarItems[pos].image = settings.imagePath + settings.items[pos].selected;     
        });
    };

Your Answer

Think you can help? Login to answer this question!