I have an error when I use StoryBoard Reference after a UITabBarController
(which is a custom one).
I found how to customise my icon image, but in my code, when I try to get this image, the value doesn't exist.
Here is my image configuration:
And there the error when I run my app:
It worked before I used a Storyboard Reference. And the Image is set as my other Tab Bar Items, so I don't understand why I get this error when I run my app.
EDIT: Where do I call the setup()
function?
I have 3 files to handle my Tab Bar.
The first one, CustomTabBarController.swift
, contains this code in viewDidLoad
:
let customTabBar = CustomTabBar(frame: self.tabBar.frame)
customTabBar.datasource = self
customTabBar.delegate = self
customTabBar.setup()
It calls the setup()
method of CustomTabBar
, which is:
func setup() {
// get tab bar items from default tab bar
tabBarItems = datasource.tabBarItemsInCustomTabBar(self)
customTabBarItems = []
tabBarButtons = []
selectedTabBarItemIndex = 0
let containers = createTabBarItemContainers()
createTabBarItems(containers)
customTabBarItems[selectedTabBarItemIndex].iconView.tintColor = UIColor(red:0.44, green:0.52, blue:1.00, alpha:1.0)
}
This function calls the setup()
function of my CustomTabBarItem
view:
func createTabBarItems(_ containers: [CGRect]) {
var index = 0
for item in tabBarItems {
let container = containers[index]
let customTabBarItem = CustomTabBarItem(frame: container)
customTabBarItem.setup(item) // HERE I call my setup() method of my Tab Bar Item
self.addSubview(customTabBarItem)
customTabBarItems.append(customTabBarItem)
let button = UIButton(frame: CGRect(x: 0, y: 0, width: container.width, height: container.height))
button.addTarget(self, action: #selector(CustomTabBar.barItemTapped(_:)), for: UIControlEvents.touchUpInside)
customTabBarItem.addSubview(button)
tabBarButtons.append(button)
index += 1
}
}