// 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
答案 0 :(得分:0)
问题正是错误描述所暗示的。您需要使您的班级符合QuizPopUpViewControllerDelegate
委托。
为此,您需要声明函数,QuizPopUpViewControllerDelegate
。
// Another Viewcontroller
class ShortlistViewController: ParentViewController , QuizPopUpViewControllerDelegate {
func ApplyNowToSendBack() {
// do something with the callback.
}
}
为避免将来提出此类问题,我建议您详细了解delegate pattern in Swift。