ionic tabscontroller make not-first active on startup - ionic-framework

When you start an ionic application with a tabbar on the bottom, it always starts the App with the first Tab active.
But I have 3 tabs, and I want the Tab in the middle to be the active Tab that starts when I open the App.
Can't find in the docs how to do this. Someone?

There is $ionicTabsDelegate for your needs. You can inject it into any controller, or your app's run block. Then you do it similar to the example:
function MyCtrl($scope, $ionicTabsDelegate) {
//use 1 to select the second tab (starts with 0)
$ionicTabsDelegate.select(1);
}
if you want to have it when your app starts, put in in your run block

Related

Ionic2: Reload the ion content when back button is pressed

How do I reload the content sitting under <ion-content> tag when back button is pressed?
The answer which is there is correct, however, it is outdated. Here is the updated answer.
Link to the Life Cycle just scroll down and you should see it.
Example:
ionViewWillEnter() {
console.log('Runs when the page is about to enter and become the active page.');
}
Just use a View Lifecycle Hook in the view you are going back you have to use for example:
onPageWillEnter() {
// You can execute what you want here and it will be executed right before you enter the view
}
Or you use a lifecycle hook on the page you are leaving then just replace onPageWillEnter() with onPageWillLeave()
With ionic beta 8 the lifecylcle events changed their names. Check out the official ionic blog for the full list of the lifecycle events.

Set tab active when an Activity loads for the first time (Android SlidingTabLayout)

Using SlidngTabLayout
, i'm not able to set the first tab as active when my activity loads for the first time. Once i click on it, it works fine. However, i need my first tab to be automatically selected when the activity starts the first time
Inside SlidingTabLayout.java i modified the InternalViewPagerListener this way,
So basically, inside onPageScrolled method, i did this.
if (position == 0)
selectedTitle.setSelected(true);
else
mTabStrip.getChildAt(0).setSelected(false);
Done! Happy coding :)

How to finish an Activity that is used in a TabSpec, as the child of TabHost

I have Main Activity which contains a TabHost.
In the TabHost I have several TabSpec which use an Intent for the content of the tab.
At certain points in my code I need to remove a tab from the TabHost, and finish the Activity that was in that tab's TabSpec.
I am able to remove the tab from the TabHost, but as soon as I call finish on that child Activity, the Main Activity terminates. I have even tried calling finish some time later, with a timer. It still kills the main activity.
How can I finish a child activity without killing the main activity?
Tab Host was decrapated by google so you shouldnt use it anymore you should replace it using actionbarsherlock its a better option for tabs.

how to load aplication from start up page each time in iphone

I have application for iphone i want to open it from start up page always but when i load first time app on ipad it loads from startup page but when i close app and second time run on ipad then it opens from the same screen from where i left i want that again it should open from startup page also.I have start up page with enter button when i click to button i move to calulations screen where i perform calculations .If i close on calculation screen the app when i again open it it opens from calculation screens not from the startup screen
In plist file add one more field
Application does not run in background : make it true
This is your perfect ans.
Second time app will be in Background thats why it is not starting with start app page. Dont allow application to run in background. Set Key "" in info.plist file
You should add in your plist that property :
UIApplicationExitsOnSuspend
This will allow your application to "restart" instead of saving its state. This will allow you to load the start up page each time.
(documentation)
Well it is discouraged by apple , according to it's documentation:-
There is no API provided for gracefully terminating an iOS application.
In iOS,user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take — turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.
Warning Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.
Here's the link to it.Anyway nobody stops you from using
exit(0) , but is discouraged.
Another way to do is is simply change your application's pList property "Application does not run in background" to true.

How to unload js script when going to next tab in jquery?

I have a site with five tabs using jquery-ui. Each loads an individual jQuery script. Now when I have loaded the second tab and go to the third tab the js out of the second tab still remains active and disturbs my actions in the third tab space.
Can someone explain me why the js out of the second tab still stays active when changing to the third tab and how I can avoid such behaviour?
Once you have loaded a script onto the page, it remains active until the page refreshes.
I don't know about unloading, but you can certainly disable the actions of a certain script depending on what it is. Could you post an example of the script causing the issues?
EDIT:
For example, if you have a script that is dependent on the tab you are in, you can condition the actions in the script with the tabs being at a certain index. A demo syntax:
//will only execute action if you are in current tab
if(tabs_ui_index == 0){
//do something
}
to get that variable (tabs_ui_index) you can do something like this:
$('#mytabs').bind('tabsselect', function(event, ui) {
tabs_ui_index = ui.index;
});
This code binds a "tabsselect" event to the element that is tabbed and sets the variable to the currently indexed tab every time a user changes a tab.
Also, you can unbind events, if you loaded a script that set a click event for a button that no longer exists, or that you are using for a different purpose now:
$("#mybutton").unbind("click");
I hope this helps. Let me know if you have any other questions.