1.创建协议
protocol VisitorViewDelegate: NSObjectProtocol{
//注册
func visitorViewDidRegister()
//登录
func visitorViewDidLogin()
}
2.声明及监听
//weak 弱引用 代理
weak var delegate: VisitorViewDelegate?
//MARK: - 监听方法
@objc private func clickRegister(){
delegate?.visitorViewDidRegister()
}
@objc private func clickLogin(){
delegate?.visitorViewDidLogin()
}
//添加监听函数
registerButton.addTarget(self, action: #selector(clickRegister), for: .touchUpInside)
loginButton.addTarget(self, action: #selector(clickLogin), for: .touchUpInside)
3.设置代理,回调函数
visitorView?.delegate = self
//MARK: - 访客视图监听方法
extension VisitorTableViewController: VisitorViewDelegate{
//注册
func visitorViewDidRegister() {
}
//登录
func visitorViewDidLogin() {
}
}
|