【发布时间】:2021-02-10 22:28:02
【问题描述】:
在 SwiftUI 中使用 UIViewController 我需要为两个按钮分配选择器。那些需要是@objc,但我得到了错误:
无法将方法标记为@objc,因为在Objective-C中无法表示参数的类型
struct ScanPreView: UIViewControllerRepresentable {
class Coordinator: NSObject {
var parent: ScanPreView
init(_ parent: ScanPreView) {
self.parent = parent
}
@objc func dismissPreviewedScanTapped(sender: ScanPreView) {
}
@objc func savePreviewedSceneTapped(sender: ScanPreView) {
}
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
func makeUIViewController(context: Context) -> ScenePreviewViewController {
let preview = ScenePreviewViewController(pointCloud: pointCloud, meshTexturing: meshTexturing, landmarks: nil)
preview.leftButton.addTarget(context.coordinator, action: #selector(Coordinator.dismissPreviewedScanTapped(sender:)), for: UIControl.Event.touchUpInside)
preview.rightButton.addTarget(context.coordinator, action: #selector(Coordinator.savePreviewedSceneTapped(sender:)), for: UIControl.Event.touchUpInside)
return preview
}
}
【问题讨论】:
标签: objective-c swift swiftui uiviewcontrollerrepresentable