2017-09-15 56 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