Closed chitvan832 closed 7 years ago
Hi @chitvan832 , can you include the whole viewDidLoad function?
@Minitour here you go
override func viewDidLoad() { super.viewDidLoad()
var icons = [String]()
icons.append("ic_home_outline")
icons.append("ic_menu")
icons.append("ic_add")
icons.append("ic_subject_outline")
icons.append("ic_profile_outline")
var selectedIcons = [String]()
selectedIcons.append("ic_menu")
selectedIcons.append("ic_menu")
selectedIcons.append("ic_add")
selectedIcons.append("ic_subject_outline")
selectedIcons.append("ic_profile")
//initializing tab bar
let tabController = AZTabBarController.insert(into: self, withTabIconNames: icons, andSelectedIconNames: selectedIcons)
tabController.set(action: {
//Your statments
print("Hello Categoty")
tabController.moveSelectionIndicator(toIndex: 1,animated:true)
}, atIndex: 1)
tabController.set(action: {
//Your statments
print("Hello Home")
tabController.moveSelectionIndicator(toIndex: 0,animated:true)
}, atIndex: 0)
tabController.set(action: {
//Your statments
print("Hello Account")
tabController.moveSelectionIndicator(toIndex: 4,animated:true)
}, atIndex: 4)
//tabController.set(viewController: UINavigationController(rootViewController: instance), atIndex: 0)
tabController.set(viewController: instance, atIndex: 0)
tabController.defaultColor = UIColor.white
tabController.buttonsBackgroundColor = UIColor.black
tabController.selectionIndicatorColor = UIColor.red
tabController.selectionIndicatorHeight = 3
tabController.tabBarHeight = view.frame.height*0.1
}
@chitvan832 Why are you using the Set Action
function in order to move the selection indicator?
The selection indicator will automatically move if you have a controller set on that index.
Also at which part do you add a View Controller
at index 1?
Setting an action on an index doesn't mean the selection indicator can move to it. It only means you assign an action to that index.
When to use Set Action
: Use this when you want to trigger something that doesn't really need it's own View Controller. For example the Camera on Instagram.
When to use Set View Controller
: Use this when you want to have a view to display at that index.
@Minitour actually i didnt assigned any view controller till that time and was working on the UI , is it possible in any case that the problem is arising because of the same , should i first assign the view controller , and if yes can you tell how to do so
If you want to see the effect of the tab bar you can set a blank view controller by doing:
tabController.set(viewController: UIViewController(),atIndex: 1)
@Minitour here is my main ViewController, at index 1 i want VC1 , please check the screenshots
import Foundation import UIKit import AZTabBar
class HomeViewController: UIViewController { var tabController:AZTabBarController!
override func viewDidLoad() {
super.viewDidLoad()
var icons = [String]()
icons.append("ic_home_outline")
icons.append("ic_menu")
icons.append("ic_add")
icons.append("ic_subject_outline")
icons.append("ic_profile_outline")
var selectedIcons = [String]()
selectedIcons.append("ic_menu")
selectedIcons.append("ic_menu")
selectedIcons.append("ic_add")
selectedIcons.append("ic_subject_outline")
selectedIcons.append("ic_profile")
//initializing tab bar
let tabController = AZTabBarController.insert(into: self, withTabIconNames: icons, andSelectedIconNames: selectedIcons)
tabController.set(viewController: VC1(), atIndex: 1)
tabController.defaultColor = UIColor.white
tabController.buttonsBackgroundColor = UIColor.black
tabController.selectionIndicatorColor = UIColor.red
tabController.selectionIndicatorHeight = 3
tabController.tabBarHeight = view.frame.height*0.1
}
}
@chitvan832
Is your VC1 class initialized from storyboard? If it is then you need to init it like this:
let myViewControllerInstance = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "CustomViewController")
if it's not then it should work find the way you are doing it.
Also for the icon, use tabController.selectedColor
(because the default is black)
@Minitour finally it worked... thanks alot , i didnt knew that we need to initialize our View controller like that.. thanks once again
@chitvan832 No problem, glad to help 😉
hi i am using AZTabBarController as a pod in my project, in myviewDidLoad of Main VC i have : tabController.set(viewController: instanceControllerAccount, atIndex: 1)
but it show nothing except the selector indicator shifting to that tab