Sunday, August 14, 2022
HomeiOS Developmentios - The best way to move parameter in button's addtarget

ios – The best way to move parameter in button’s addtarget

I’ve a backside sheet, and on that sheet there’s a button. I would like that when i faucet to that button it go to the web page it’s associated to. So, i related 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) {
        tremendous.init(coder: aDecoder)!

    required override init(body: CGRect) {
        tremendous.init(body: body)

Within the collectionview, the place i’m clicking on button, i name these strategies.

let button = SheetOpenPageButton()
                button.tag = ?? 1
                button.addTarget(self, motion: #selector(goToRestuarantFromStory(_ :)), for: .touchUpInside)

  @objc func goToRestuarantFromStory(_ sender : UIButton) {
        let restuarantVC = UIStoryboard(identify: "Cafe", bundle: .major).instantiateViewController(withIdentifier: "RestuarantViewController") as! RestuarantViewController
        restuarantVC.networkId = sender.tag
        navigationController?.pushViewController(restuarantVC, animated: true)
        vc.dismiss(animated: true, completion: nil)

Right here i’m passing parameter in addtarget utilizing button’s tag.
However, when tapping on button it does not give a response. I do not know learn how to clear up this.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments