I am trying to set the items for my Tab Bar from the TabBarViewController.
However, once I set the items, here's the error I get:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
Here's the code:
func imageWithImageSize(image:UIImage , newSize:CGSize) -> UIImage{
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0);
image.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
let image1 = imageWithImageSize(UIImage(named: "Home.png")!, newSize: CGSizeMake(30, 30))
let homeItem = UITabBarItem(title: "Home", image: image1, selectedImage: image1)
let image2 = imageWithImageSize(UIImage(named: "Profile.png")!, newSize: CGSizeMake(30, 30))
let profileItem = UITabBarItem(title: "Profile", image: image2, selectedImage: image2)
self.tabBar.setItems([homeItem,profileItem, homeItem, homeItem], animated: false)
Is there a solution around it?