Swift:类的多重继承错误UIViewController和UIIMagePickerController

cph*_*ill 4 uiviewcontroller ios swift

我手动添加了两个额外的控制器(UINavigationControllerDelegate&UIImagePickerController)到a UIViewController,我收到一个错误后添加UIImagePickerController说,

Multiple inheritance from classes UIViewController and UIImagePickerController

我不确定如何解释和解决这个问题.

由于这个错误,当我使用该image.delegate方法并将其设置为等于时,我也会看到一个self

Type ViewController does not conform to protocol UIImagePickerControllerDelegate

码:

class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerController {

    @IBAction func pickImage(sender: UIButton) {

        var image = UIImagePickerController()
        image.delegate = self
        image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
        image.allowsEditing = false

        self.presentViewController(image, animated: true, completion: nil)


    }
Run Code Online (Sandbox Code Playgroud)

rde*_*mar 25

您应该在第一行中使用UIImagePickerControllerDelegate,而不是UIPickerViewController.系统认为你试图让你的控制器继承UIViewController和UIImagePickerController这是不允许的.