【发布时间】:2021-07-23 10:44:35
【问题描述】:
我有 SwiftUI 页面,它是从 UIKit 视图导航的。我想给这个页面设置一个标题,我正在做的是
// code of UIKit view
let controller = UIHostingController(rootView: SwiftUIView())
controller.title = "title"
MyNavigationManager.present(controller)
有没有办法可以在 SwiftUI 中访问主机控制器?
然后我可以编写如下代码
self.hostingController?.title = "title"
【问题讨论】:
-
最后我选择了一个简单的方法,在宿主控制器中,将 self 传递给 SwiftUI rootView.hostingController = self
标签: swiftui uihostingcontroller