objective-c - SwiftUI 协调器 : method can not be marked @objc

标签 objective-c swift swiftui uiviewcontrollerrepresentable

SwiftUI 中使用 UIViewController 我需要为两个按钮分配选择器。这些需要是 @objc 但我收到错误:

Method cannot be marked @objc because the type of the parameter cannot be represented in 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
    }
}

最佳答案

您不需要在那里查看,因此如果您需要操作签名,只需使用 Any 即可,例如

@objc func dismissPreviewedScanTapped(sender: Any) {
    
}

关于objective-c - SwiftUI 协调器 : method can not be marked @objc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64574838/

相关文章:

objective-c - NSMutableArray 在索引处插入对象

objective-c - 我应该如何从设备运动中计算 "world coordinates"的 3 轴?

swift - 为什么核心数据不会在 swiftui 类中加载,但会在结构 View 中加载

xcode - SwiftUI:listRowInsets 未按预期工作

objective-c - 如何更新 splitViewController 中的详细 View ?

iphone - 计算核心数据中的不同项目

ios - 创建一个包含 UIAlertView、UIActivityIndi​​cator 等函数的类,并在各种 viewController 中回调它们

ios - 在 SwiftUI 中使用像 MVC 这样的设计模式

ios - 将可选字符串转换为日期

ios - 如何在 Swift 中删除 UIMenuController 默认项