Last active
November 19, 2015 03:41
-
-
Save ctrevarthen/9a4151e458eba6d24763 to your computer and use it in GitHub Desktop.
Swipe to delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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