2017-09-15 58 views
1

我仍然是Swift编程的初学者,我正在尝试构建一个非常基本的iOS应用程序。该应用程序要求用户拍照并在照片编辑器上进行编辑。我遇到使用editor.photoEditorDelegate = self的问题。我该如何纠正editor.photoEditorDelegate = self?

这是他的例子中使用的照片编辑器的开发人员,它没有给出任何问题,但它不适合我。它给出了一个错误:

无法指定类型'PhotosViewController?'的值键入'PhotoEditorDelegate?'

我试图与修复:

editor.photoEditorDelegate = self as? PhotoEditorDelegate 

,但它只是让当编辑器被称为应用程序崩溃。

我宣布与编辑:

let editor = PhotoEditorViewController(nibName:"PhotoEditorViewController",bundle: Bundle(for: PhotoEditorViewController.self)) 

回答

-1

你需要让你的PhotosViewController您PhotoEditorDelegate:

class PhotosViewController: PhotoEditorDelegate { 

... 
+1

这是一个质量很低的答案。 –

1

错误的道理不言而喻!您需要将此委托添加到您的类名“PhotoEditorDelegate”

这是一个基于信息的示例代码您提供

class PhotosViewController: PhotoEditorDelegate { 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     let editor = PhotoEditorViewController(nibName:"PhotoEditorViewController",bundle: Bundle(for: PhotoEditorViewController.self)) 

     editor.photoEditorDelegate = self 


    // Do any additional setup after loading the view. 
    } 



} 
+0

这不是“不言自明”,这就是为什么要问这个问题。 – Shades

+1

@Shades“无法分配'PhotosViewController'类型的值键入'PhotoEditorDelegate?'“这怎么能不容易理解? – Siyavash