Answer the question
In order to leave comments, you need to log in
How to correctly implement the delegate in this case?
Purpose
When clicking on a custom button, in another custom UIView subclass, do something.
What I did
This is a custom button:
protocol CHNumberKeyboardModifyDelegate: class where Self: CHDotsContainer {
func modify()
}
class CHNumberKeyboardButton: UIButton {
weak var chNumberKeyboardModifyDelegate: CHNumberKeyboardModifyDelegate?
@objc func touch(_ sender: UIButton!) {
chNumberKeyboardModifyDelegate?.modify()
}
}
class CHDotsContainer: UIView, CHNumberKeyboardModifyDelegate {
func modify() {
print("touched")
}
}
let button = CHNumberKeyboardButton()
button.chNumberKeyboardModifyDelegate = self
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question