ViewController不符合协议xyzDelegate

时间:2016-12-28 09:13:40

标签: swift delegates

// QuizPopUpViewController.swift
@objc protocol QuizPopUpViewControllerDelegate {
    func ApplyNowToSendBack()
}

class QuizPopUpViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate {
    weak var delegate: QuizPopUpViewControllerDelegate?
}


// giving event from here
 if isError == false {
     self.delegate?.ApplyNowToSendBack() // delegate method
    }
}

// Another Viewcontroller     
class ShortlistViewController: ParentViewController , QuizPopUpViewControllerDelegate {

}

当我将QuizPopUpViewControllerDelegate添加到ShortlistViewController时,我收到以下错误:

  

类型“ShortlistviewController”不符合协议QuizPopUpViewControllerDelegate

1 个答案:

答案 0 :(得分:0)

问题正是错误描述所暗示的。您需要使您的班级符合QuizPopUpViewControllerDelegate委托。

为此,您需要声明函数,QuizPopUpViewControllerDelegate

中的内容
   // Another Viewcontroller     
   class ShortlistViewController: ParentViewController , QuizPopUpViewControllerDelegate {
          func ApplyNowToSendBack() {
            // do something with the callback.
          }
    }

为避免将来提出此类问题,我建议您详细了解delegate pattern in Swift