New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Urgently: How can I change the selectedIndex tab? #43
Comments
I have the same issue, have you figured out a solution? |
It looks like I made it work, but I don't really like my own solution, so anyone more expert than me (meaning, everyone ;) is more than welcome to suggest a better way. If you need to start your app in a different tab from the first one, it's pretty straightforward; in AppDelegate, inside application:DidFinishLaunchingWithOptions: let ramTBC = self.window!.rootViewController as! RAMAnimatedTabBarController
ramTBC.selectedIndex = myDestination
ramTBC.setSelectIndex(from: 0, to: myDestination) // Because by default createCustomIcons() of RAMAnimatedTabBarController sets the selectedState for the item at index 0 If you need to switch programmatically from one tab to another during the execution of the app: let currentIndex : Int? = self.tabBarController?.selectedIndex
self.tabBarController?.selectedIndex = myDestination
if let ramTBC = self.tabBarController as? RAMAnimatedTabBarController,
let current = currentIndex {
ramTBC.setSelectIndex(from: current, to: myDestination)
} I hope it helps. |
I just added a new method called setSelectedTabToIndex to the RAMAnimatedTabBarController class
|
The func setSElectedTabToIndex raises null pointer exception |
Have you tried my approach?
|
@cdf1982 your soultion worked perfectly, thanks man |
@cdf1982 Thanks man! I tried the AppDelegate part and your solution worked perfectly. However, my icon is using BounceAnimation but for the initial part (the AppDelegate part), the icon gets initialised with some offset below.. Is there a way to push it back up manually in the AppDelegate (to achieve it with a workaround) because on the other times later in the app, it behaves as expected. It's just the AppDelegate part. What may be the problem? How can I overcome this do you think? Thanks |
@cdf1982 I have found other way to set up you preferred tab when app starts, use:
|
Based on @aalzanki solution, RAMAnimatedTabBarController.swift
Usage AppHelper.swift
and call above function from the other ViewController class
@aalzanki Thanks for your answer to solved my issue 👍 |
When I use tabBarController?.selectedIndex it doesn't change the color in the animated tab, and I have tried using setSelectIndex() function but it didn't work, I really like this library but I have a deadline. Thanks in advance.
The text was updated successfully, but these errors were encountered: