我已经做了一个自定义的UIViewController调用ViewControllerA并希望能够使用它,所以我做了一个UIViewControllerRepresentable调用, ViewControllerARepresentable如下所示,但问题是,当我ViewControllerARepresentable在 SwiftUI 视图中调用并传递一个值时stringToUpdateTextView,ViewControllerA该htmlTextView(UITextView)inViewControllerA是nil,我是不知道为什么。
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)