Andrea Toso Andrea Toso - 1 year ago 72
Swift Question

Access to navigationController in a customCell

I have

with customCells and in the first one (indexPath 0) I have a

I'd want that when I click it, I go into another ViewController but I can't access to the
because my cell is a

How can I get the access to the

Answer Source

You can set the Button action pragmatically in your current ViewController, inside CollectionViewDataSource method cellForItemAtIndexPath for that cell this way.

cell.btnAdd.addTarget(self, action: #selector(self.buttonClicked(_:)), forControlEvents: .TouchUpInside)

After that add this method in your ViewController

func buttonClicked(sender: UIButton) {
    //perform navigation now
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download