小编Di *_*erd的帖子

具有 UIViewcontrollerRepresentable 的自定义 UIViewController,其 UITextView 在 SwiftUI 中调用时崩溃或为零

我已经做了一个自定义的UIViewController调用ViewControllerA并希望能够使用它,所以我做了一个UIViewControllerRepresentable调用, ViewControllerARepresentable如下所示,但问题是,当我ViewControllerARepresentable在 SwiftUI 视图中调用并传递一个值时stringToUpdateTextViewViewControllerAhtmlTextView(UITextView)inViewControllerAnil,我是不知道为什么。

ViewControllerARepresentable(stringToUpdateTextView: "<html>Send some Html Text as string here</html>")
Run Code Online (Sandbox Code Playgroud)

ViewControllerA可表示

public struct ViewControllerARepresentable: UIViewControllerRepresentable {
  var stringToUpdateTextView: String

  public func makeUIViewController(context: Context) -> ViewControllerA {
    let viewcontrollerA = ViewControllerA(testString: testingString)

    return viewcontrollerA
  }

  public func updateUIViewController(_ uiViewController: ViewControllerA, context: Context) {}
}
Run Code Online (Sandbox Code Playgroud)

视图控制器A

open class ViewControllerA: UIViewController {

  public var stringToUpdateTextView: String

  override open func viewDidLoad() {
    super.viewDidLoad() …
Run Code Online (Sandbox Code Playgroud)

nsattributedstring swiftui uiviewcontrollerrepresentable

0
推荐指数
1
解决办法
1892
查看次数