I'm trying to wrap a UITabBarController in a SwiftUI view using UIViewControllerRepresentable but ran into a problem that I haven't been able to solve for days. I've looked through every single possible thread and have tried all proposed solutions with no luck. Any help would be tremendously appreciated.
TabViewController.swift
import UIKit
import ResearchKit
import CareKit
import SwiftUI
struct TabBarView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UITabBarController {
let tabBarViewController = TabBarViewController()
return tabBarViewController
}
func updateUIViewController(_ uiViewController: UITabBarController, context: Context) {
}
typealias UIViewControllerType = UITabBarController
}
class TabBarViewController: UITabBarController {
fileprivate let carePlanStoreManager = CarePlanStoreManager.sharedCarePlanStoreManager
fileprivate let carePlanData: CarePlanData
fileprivate var symptomTrackerViewController: OCKSymptomTrackerViewController? = nil
fileprivate var insightsViewController: OCKInsightsViewController? = nil
fileprivate var insightChart: OCKBarChart? = nil
required init?(coder aDecoder: NSCoder) {
carePlanData = CarePlanData(carePlanStore: carePlanStoreManager.store)
super.init(coder: aDecoder)
carePlanStoreManager.delegate = self
carePlanStoreManager.updateInsights()
let careCardStack = createCareCardStack()
let symptomTrackerStack = createSymptomTrackerStack()
let insightsStack = createInsightsStack()
let connectStack = createConnectStack()
self.viewControllers = [careCardStack,
symptomTrackerStack,
insightsStack,
connectStack]
tabBar.tintColor = UIColor.systemTeal
tabBar.barTintColor = UIColor.white
}
I've also attached a screenshot that displays the exact error.
init(coder:)and now that is the only initializer you have. When you sayTabBarViewController()you are calling a different initializer,init(), and it doesn't exist. It's as if you had said to me "here, take these blue shoes" and then said "please give me the red shoes". What red shoes?