Search code examples
iosswiftuibuttoncustom-cell

UIButton in custom cell not working


I have a button in a custom cell

class CardTableViewCell: UITableViewCell {
    @IBOutlet weak var detailsButton: UIButton!
}

in my view controller then I do this

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    //.....more code....
    openDealCell.detailsButton.addTarget(self, action: "push:", forControlEvents: UIControlEvents.TouchUpInside)      
}

and then:

func push(sender:AnyObject) {
    println("tap")
}

But when I clicked the button nothing happens.

What I am doing wrong?


Solution

  • Fix it! The problem was not in the code but in my cell in the storyboard:

    enter image description here

    where user interaction for the cell wasn't enabled and all the other view didn't allow the user interaction.

    enter image description here