Skip to content

Instantly share code, notes, and snippets.

@ctrevarthen
Last active November 19, 2015 03:40
Show Gist options
  • Save ctrevarthen/1a999d68c8f2de64fa43 to your computer and use it in GitHub Desktop.
Save ctrevarthen/1a999d68c8f2de64fa43 to your computer and use it in GitHub Desktop.
ShopQuick: Delete with utility
func swipeableTableViewCell(cell: SWTableViewCell!, didTriggerRightUtilityButtonWithIndex index: Int) {
switch index {
case RightUtilityButtons.Delete.rawValue:
if let indexPath = self.shoppingListTableView.indexPathForCell(cell) as NSIndexPath! {
self.shoppingListTableView.beginUpdates()
self.shoppingListTableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Bottom)
self.shoppingListManager.removeProductAtIndex(indexPath.row)
self.shoppingListTableView.endUpdates()
}
default:
break
}
}
/******** REMOVED ********
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
if let removedCell = tableView.cellForRowAtIndexPath(indexPath) as? ProductCell {
let removedProduct = Product(name: removedCell.productNameLabel.text!, qty: 1)
self.shoppingListManager.removeProduct(removedProduct)
removedCell.endEditing(false)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
}
}
}
func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) as? ProductCell {
cell.startEditing()
}
}
func tableView(tableView: UITableView, didEndEditingRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) as? ProductCell {
cell.endEditing(false)
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment