Scenario: I have a table view and a custom button cell. In controller of cell I have made a delegate to call a function of MainController. Issue is my cell button action is firing but the delete function not.
CustomCell Controller:
import UIKit
protocol CustChatButtonDelegate: class {
func chatActionClick(cell: CustButtonCell)
}
class CustButtonCell: UITableViewCell {
var delegete:CustChatButtonDelegate?
@IBOutlet weak var btnChat: UIButton!
override func prepareForReuse() {
super.prepareForReuse()
// self.delegete=nil
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
@IBAction func btnChatActionClick(_ sender: Any) {
print("btn click")
self.delegete?.chatActionClick(cell: self)
}
}
MainController:
import UIKit
class ChatController: UIViewController ,UITableViewDelegate, UITableViewDataSource, ChatButtonDelegate,CustChatButtonDelegate {
func chatActionClick(cell: CustButtonCell) {
print("btnClicked")
}
}