簡體   English   中英

如何從其父 UIViewController 訪問 SwiftUI 視圖?

[英]How to access a SwiftUI view from its parent UIViewController?

我正在使用 UIViewController 使用 UIHostingController 的 SwiftUI 視圖。

這不起作用:

viewController.contentView.first as? SwiftUIView

因為它不再是 SwiftUI 視圖,而是 UIView。

是否可以從 UIViewController 取回 SwiftUI 視圖?

創建視圖時,只需將視圖控制器變量的引用保存到 SwiftUI 視圖即可。

class ViewController: UIViewController {
  // Store the reference to the SwiftUI view after creating it.
  var swiftUiView: SwiftUiView?
  // ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM