如何在UITableViewCell中点击单元格的button,而不用动作单元格的继续
我的自定义单元格有2个button,每个自定义单元格也执行一个segue。
seguefunction正常,问题来自我的button从未被解雇的事实。 如果我点击他们然后赛格被解雇,但不是button。 如何克服这一点?
这里是如何定义button的动作的代码:
在表格视图控制器中
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)
select器的目标函数是有效的,我没有错误。 button只是从来没有被解雇。
如果不是那么简单,需要更多的代码就问我吧!
迄今为止我find的最佳解决scheme是:
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] }
有我的行动作为轻扫button,它更“iOS”的风格