首页 > 解决方案 > 如何在现有 Storyboard Tab Bar Controller 中使用 Hosting Controller for SwiftUI?

问题描述

我正在尝试使用托管控制器将 SwiftUI 视图包含在现有的故事板标签栏控制器中。我已经使用Relationship Segue 将Hosting View Controller 连接到Storyboard 上的Tab Bar Controller。以下是我从阅读其他帖子中尝试过的,但我得到的只是黑屏。任何帮助,将不胜感激。谢谢你。

在此处输入图像描述

import UIKit
import SwiftUI

class SingleSearchHost: UIHostingController<SingleSearch>{
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder, rootView: SingleSearch())
    }
}

标签: swiftswiftuistoryboardtabbarcontrolleruihostingcontroller

解决方案


我的问题的答案是将类分配给 Storyboard 身份检查器中的主机控制器。感谢@Adam 回答这个问题!


推荐阅读