I am trying to setup UITabBarController, it works fine on iphone but crashes on ipad ios 17
the iphone have the save ios version as the ipad
I use xcode version 15.4
This is my tabbar controller
class DashboardVC: UITabBarController, UITabBarControllerDelegate {
var presenter: DashboardPresentation?
var controllersList: [UIViewController]?
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.isHidden = true
// self.navigationItem.title = "Check Me".localized()
self.delegate = self
self.tabBar.shadowImage = nil
self.tabBar.layer.borderWidth = 1
self.tabBar.layer.borderColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
self.tabBar.clipsToBounds = true
setubTabControllers()
}
func setubTabControllers() {
self.tabBar.tintColor = #colorLiteral(red: 0.05490196078, green: 0.3764705882, blue: 0.8980392157, alpha: 1)
self.tabBar.barTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
self.tabBar.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
self.tabBar.unselectedItemTintColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
self.tabBar.isTranslucent = false
self.tabBar.itemPositioning = .centered
let homeVC = HomeRouter.assembleModule(title: msgTitle, message: message, goToChat: goToChat, returnNav: true)
homeVC.tabBarItem = UITabBarItem(title: "Home".localized(), image: UIImage(named: "Home-inactive")?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage(named: "Home")?.withRenderingMode(.alwaysOriginal))
let favVC = NotificationsListRouter.assembleModule(dashboardDelegate: self, returnNav: true)
favVC.tabBarItem = UITabBarItem(title: "Notifications".localized(), image: UIImage(named: "Notifications-inactive")?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage(named: "Notifications-active")?.withRenderingMode(.alwaysOriginal))
let searchVC = ResultsRouter.assembleModule(returnNav: true)
searchVC.tabBarItem = UITabBarItem(title: "Results".localized(), image: UIImage(named: "result-inactive")?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage(named: "result-active")?.withRenderingMode(.alwaysOriginal))
let accountVC = AccountRouter.assembleModule(returnNav: true)
accountVC.tabBarItem = UITabBarItem(title: "Profile".localized(), image: UIImage(named: "profile-inactive")?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage(named: "profile-active")?.withRenderingMode(.alwaysOriginal))
if UIDevice.current.userInterfaceIdiom == .pad {
homeVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .normal)
favVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .normal)
searchVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .normal)
accountVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .normal)
} else {
homeVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)], for: .normal)
favVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)], for: .normal)
searchVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)], for: .normal)
accountVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)], for: .normal)
}
controllersList = [homeVC, favVC, searchVC, accountVC]
self.viewControllers = controllersList
}
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
}
}
this is the error when the app crashed
*** Assertion failure in UITraitCollection * _Nonnull _UIGetCurrentFallbackTraitCollection(void)(), _UIFallbackEnvironment_NonARC.m:117
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'A trait environment returned a trait collection with unspecified values for traits that are not allowed to be unspecified. This is a serious application bug and will cause undefined behavior. This issue may be caused by your class overriding the traitCollection property getter, which is not supported. Make sure to use the appropriate API if you are trying to override traits. Trait Environment: <UITabBarSwappableImageView: 0x105b2bf90; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; image = <UIImage:0x6000030058c0 CGImage anonymous; (23 23)@2>; layer = <CALayer: 0x600000293bc0>>; Trait Collection: <UITraitCollection: 0x105a54950; HorizontalSizeClass = Compact, PreferredContentSizeCategory = L>'
I tried to debug the code to detect why this happens only on ipad but found nothing
2