I'm developing an iOS application using SwiftUI, but I need to develop with UIKit some features what there are no supported in SwiftUI.
So, I'm developing UIKit in SwiftUI, but UIKit's IBOutlet is nil so I can't update UIKit value. Is there any way to declare IBOutlet manually?
class StoreDetailViewController : UIViewController, CLLocationManagerDelegate, updateValue{
@IBOutlet weak var mapView: NMFMapView!
var lat : Double = 0.0
var lon : Double = 0.0
let marker = NMFMarker()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
view.addSubview(mapView)
}
@IBSegueAction func loadSwiftUI(_ coder: NSCoder) -> UIViewController? {
return UIHostingController(coder: coder, rootView: storeDetail())
}
func removeMarker(){
marker.mapView = nil
}
func setMarker(lat: Double, lon: Double){
print("setting marker, ", lat, lon)
marker.position = NMGLatLng(lat: lat, lng: lon)
marker.mapView = self.mapView
}
}
struct loadViewController: UIViewControllerRepresentable{
var delegate : updateValue?
func updateUIViewController(_ uiViewController: StoreDetailViewController, context: Context) {
}
func setPosition(latitude: String, longitude: String){
print("position : ", latitude, longitude)
self.delegate?.setMarker(lat: Double(latitude)!, lon: Double(longitude)!)
StoreDetailViewController().setMarker(lat: Double(latitude)!, lon: Double(longitude)!)
delegate?.setMarker(lat: Double(latitude)!, lon: Double(longitude)!)
}
typealias UIViewControllerType = StoreDetailViewController
func makeUIViewController(context: UIViewControllerRepresentableContext<loadViewController>) -> UIViewControllerType {
UIStoryboard(name: "storeDetail", bundle: nil).instantiateViewController(identifier: "Store Detail View Controller") as! StoreDetailViewController
}
}
question from:
https://stackoverflow.com/questions/65713796/swift-iboutlet-is-nil-but-it-is-connected-storyboard 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…