I have a bottom sheet, and on that sheet there is a button. I want that when i tap to that button it go to the page it is related to. So, i connected that from storyboard to code
@IBOutlet weak var openPage: SheetOpenPageButton!
And wrote extension for the button.
class SheetOpenPageButton: UIButton {
var navigationController: UINavigationController?
override var isSelected: Bool {
didSet {
if isSelected {
self.backgroundColor = UIColor(named: "CustomRed")
} else {
self.backgroundColor = UIColor(named: "CustomGray")
}
}
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
required override init(frame: CGRect) {
super.init(frame: frame)
}
}
In the collectionview, where i am clicking on button, i call these methods.
let button = SheetOpenPageButton()
button.tag = cell.id ?? 1
button.addTarget(self, action: #selector(goToRestuarantFromStory(_ :)), for: .touchUpInside)
@objc func goToRestuarantFromStory(_ sender : UIButton) {
let restuarantVC = UIStoryboard(name: "Cafe", bundle: .main).instantiateViewController(withIdentifier: "RestuarantViewController") as! RestuarantViewController
restuarantVC.networkId = sender.tag
navigationController?.pushViewController(restuarantVC, animated: true)
print("smth")
removeSubview()
removeSubviewSpb()
vc.dismiss(animated: true, completion: nil)
}
Here i am passing parameter in addtarget using button's tag. But, when tapping on button it doesn't give a reaction. I don't know how to solve this.