Swift 在扩展中切换视图控制器

Swift 在扩展中切换视图控制器,swift,Swift,在我的视图控制器中有一个扩展,现在,我试图添加到扩展底部的是一个@iAction按钮,这样我的用户可以点击按钮,然后检查照片是否拍摄,然后转到下一个视图控制器,但它不允许我添加@iAction,它说只有实例方法可以声明为@iAction 我该怎么做才能让我的用户点击一个按钮来检查图像是否被拍摄,然后将我的用户带到下一个视图控制器 extension BackroundCheckViewController: UIImagePickerControllerDelegate, U

在我的视图控制器中有一个扩展,现在,我试图添加到扩展底部的是一个@iAction按钮,这样我的用户可以点击按钮,然后检查照片是否拍摄,然后转到下一个视图控制器,但它不允许我添加@iAction,它说只有实例方法可以声明为@iAction

我该怎么做才能让我的用户点击一个按钮来检查图像是否被拍摄,然后将我的用户带到下一个视图控制器


    extension BackroundCheckViewController: UIImagePickerControllerDelegate, 
    UINavigationControllerDelegate {
    //cancel
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    picker.dismiss(animated: true, completion: nil)
                       
    }
    //pick an image
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo 
    info: [UIImagePickerController.InfoKey : Any]) {
                       
    //get the image the selected
    if let pickedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
                           
    self.ProfilePictureImageView.image = pickedImage
                        
    picker.dismiss(animated: true, completion: nil)
                        
    //upload to firebase
    PhotoService.savePhoto(image: pickedImage)
                    
                    }
                    
    // navigate to somewhere else
                    
                        
            }
                    
        }

您需要在主控制器声明中添加所有@IBOutlet和@IBAction,不能在扩展中添加它们

class BackroundCheckViewController: UIViewController {
    //...
    @IBAction func buttonTapped(_ sender: UIButton) {
        print("Got the action here")
        if ProfilePictureImageView.image != nil {
            print("User has picked an image navigating to somewhere..")
            let myViewController = MyViewController()
            if let navigationController = navigationController {
                navigationController.pushViewController(myViewController, animated: true)
            } else {
                present(myViewController, animated: true)
            }
        }
    }
}

好的,在我将它们添加到主控制器声明中之后,我应该键入什么代码,以便它们知道只有在用户选择了图像后才能工作?在imageView的操作中添加一个复选框。如果图像确实导航到另一个视图控制器,则该图像具有图像。检查更新的代码,我添加了一个示例。