Я создал пользовательский UIViewController
с именем ViewControllerA
и хочу иметь возможность его использовать, поэтому я сделал UIViewControllerRepresentable
с именем ViewControllerARepresentable
, как показано ниже, но проблема в том, что когда я вызываю ViewControllerARepresentable
в мой SwiftUI просматривает и передает значение для stringToUpdateTextView
, ViewControllerA
говорит, что htmlTextView(UITextView)
в ViewControllerA
равно nil
, и я не уверен, почему.
ViewControllerARepresentable(stringToUpdateTextView: "<html>Send some Html Text as string here</html>")
ViewControllerARepresentable
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) {}
}
ViewControllerA
open class ViewControllerA: UIViewController {
public var stringToUpdateTextView: String
override open func viewDidLoad() {
super.viewDidLoad()
htmlTextView.text = stringToUpdateTextView
}
@IBOutlet weak var htmlTextView: UITextView!
public init(testString: String) {
self.testString = testString
super.init(nibName: nil, bundle: nil)
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Cra sh встречается в htmlTextView.text = stringToUpdateTextView
, говоря, что htmlTextView.text равен нулю, даже если это IBOutlet. Любое изменение, внесенное в htmlTextView, например, цвет фона, et c, также вызывает ошибку sh при вызове в viewDidAppear или viewDidLoad