步骤1、创建协议
@objc public protocol NavBarDelegate: NSObjectProtocol {
@objc optional func leftButtonAciton()
@objc optional func rightButtonAciton()
}
步骤2、委托方调用代理方
weak open var delegate:NavBarDelegate?
@objc func letfButtonOnClick(){
if let delegate =self.delegate, delegate.responds(to:#selector(NavBarDelegate.leftButtonAciton)) { delegate.leftButtonAciton?()
}
}
步骤3、代理方实现方法
extension ViewController:NavBarDelegate{
internal func leftButtonAciton(){
print("leftButtonAciton")
}
internal func rightButtonAciton(){
print("rightButtonAciton")
}
}