问题
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!
回答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
来源:https://stackoverflow.com/questions/33494776/how-to-tap-cells-buttons-in-uitableviewcell-without-actionning-the-cells-segue