1.首先,table view 中左滑能够出现编辑、删除等自定义按钮
2.其次,点击编辑能进入编辑界面
3.最后,点击删除能够删除数据
4.题外话,可以自定义更多功能的按钮
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "删除") { (action, index) in
self.items.removeAtIndex(indexPath.row)
let indexPaths = [indexPath]
tableView.deleteRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic)
}
delete.backgroundColor = UIColor.redColor()
let more = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "编辑") { (action, index) in
let editItemNavigationController = self.storyboard!.instantiateViewControllerWithIdentifier("EditItemNavigationController") as! UINavigationController
let controller = editItemNavigationController.topViewController as! AddItemViewController
controller.delegate = self
controller.itemToEdit = self.items[indexPath.row]
self.presentViewController(editItemNavigationController, animated: true, completion: nil)
}
more.backgroundColor = UIColor.orangeColor()
return [delete,more]
}