table view 中左滑出现编辑、删除等自定义按钮

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]
        
    }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,192评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 15,430评论 4 61
  • 我认真的分析了一下我的现状,我白天要带孩子,这个是没有办法的,没有人可以帮忙,我就是带孩子的主力,白天我只能趁孩子...
    破茧人阅读 210评论 5 3
  • (四)缺 2016年12月23日。 重庆。 他在寒风中稍稍抱怨了一句冷,他就已伸出手去试他衣服的厚度,始于习惯,源...
    橙多粒啊阅读 700评论 0 2
  • 你这一滴水 是要改变整条河流的方向? 你就站在那,别动 且看这汹涌而下 似千军万马 一下就能把你冲垮 你说你不怕?...
    艾任阅读 266评论 0 0

友情链接更多精彩内容