在 UIViewControllerRepresentable 结构中,调用中缺少参数 'coder' 的参数

Missing argument for parameter 'coder' in call, in UIViewControllerRepresentable struct

我正在尝试使用 UIViewControllerRepresentableUITabBarController 包装在 SwiftUI 视图中,但是 运行 变成了我遇到的问题好几天了都没能解决。我查看了每一个可能的线程,并尝试了所有建议的解决方案,但没有成功。任何帮助将不胜感激。

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
  }

我还附上了显示确切错误的屏幕截图。

尝试将所有内容移动到 init,如下所示(在这种情况下您不需要编码器)

class TabBarViewController: UITabBarController {
    fileprivate let carePlanData: CarePlanData
    fileprivate var symptomTrackerViewController: OCKSymptomTrackerViewController? = nil
    fileprivate var insightsViewController: OCKInsightsViewController? = nil
    fileprivate var insightChart: OCKBarChart? = nil
    
    fileprivate let carePlanStoreManager = CarePlanStoreManager.sharedCarePlanStoreManager
    init() {
        carePlanData = CarePlanData(carePlanStore: carePlanStoreManager.store)
        
        super.init(nibName: nil, bundle: nil)
        
        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
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}