0

My custom cell have 2 buttons, and each custom cell also perform a segue.

The segue is functionning properly, the problem come from the fact that my buttons are never fired. If I click on them then the segue is fired, but not the button. How to overcome this?

Here goes the code of how the button's actions are defined :

In the table view controller

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(CCELL.WISHCELL, forIndexPath: indexPath) as! WishCell
    let row = indexPath.row
    let product = products.elements[row]


    // Setup the 2 cell buttons
    cell.removeButton.tag = indexPath.row
    cell.addToCartButton.tag = indexPath.row
    cell.removeButton.addTarget(self, action: "removeFromWishList:", forControlEvents: .TouchUpInside)
    cell.addToCartButton.addTarget(self, action: "addToCart", forControlEvents: .TouchUpInside)

the functions targette by the selectors are valid, I have no error. Buttons are just never fired.

If it's not that trivial and more code is needed just ask me!

  • cell.selection = none try this – engmahsa Nov 03 '15 at 08:51
  • I don't have the property `selection` on my cells –  Nov 03 '15 at 08:55
  • all table view Cells have this property , you can check it at story board – engmahsa Nov 03 '15 at 08:58
  • Don't set the action on the button to perform the segues, rather link the segues from the view controller object in the storyboard and use `performSegueWithIdentifier` in your button action code – Paulw11 Nov 03 '15 at 08:58
  • The action of performing segue is not on the button. In the storyboard i connected the segue to the cell. The button is supposed to call another action –  Nov 03 '15 at 09:00
  • Check that the buttons can be placed under the `contentView` of the cell – tuledev Nov 03 '15 at 09:02
  • The buttons are INSIDE the contentView, should they be outside? I tried to move them but without success, I mean I can't move them out, storyboard sont let me. –  Nov 03 '15 at 09:04
  • Did you try explicitly declare userInteructionEnabled = YES for cell's contentView and for buttons? What you want to achieve definitely should work, it means you are doing something wrong – Injectios Nov 03 '15 at 09:06
  • @Injectios Just tried, didn't changed anything :/ –  Nov 03 '15 at 09:07
  • 1
    same questions - http://stackoverflow.com/questions/17290526/uibutton-inside-uitableviewcell , as a workaround you can disable "selection" for UITableView and put gestures enstead – Injectios Nov 03 '15 at 09:11
  • @Injectios Yhea, but I think it's not meant to be. Thanks for the solution but I'll keep to my answer I think –  Nov 03 '15 at 09:15
  • So the segue is happening before the buttons tasks are being executed? In a sense we just need to have the segue happen later vs first? – Caleb Bach Nov 03 '15 at 09:20
  • @CalebBach Yhea, it should be this way for this problem to be solved. But now I find my below answer more elegant for iOS. –  Nov 03 '15 at 09:22
  • @CalebBach If you have a way to do this just post it as answer I'll accept it if it's working –  Nov 03 '15 at 09:22

1 Answers1

1

The best solution I found so far:

override func tableView(tableView: UITableView,     editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .Destructive, title: "Delete") { (action, indexPath) in
    // delete item at indexPath
}
  let share = UITableViewRowAction(style: .Normal, title: "Disable") { (action, indexPath) in
    // share item at indexPath
}

  share.backgroundColor = UIColor.blueColor()

  return [delete, share]
}

Having my actions as swipe buttons, it's more "iOS" style