UITableView定制左滑效果

定制左滑效果
UITableViewRowAction类

object defines a single action to present when the user swipes horizontally in a table

类的属性

  • style: UITableViewRowActionStyle
    按钮的style,defaultnormal效果如上图
  • title: String?
    按钮的标题啦
  • backgroundColor: UIColor? 按钮的颜色

初始化方法

convenience init(style: UITableViewRowActionStyle, title: String?, handler: (UITableViewRowAction, IndexPath) -> Void)

handler即使点击时调用的方法。

如何实现效果

  1. 初始化UITableViewRowAction

        let action1 = UITableViewRowAction.init(style: .Normal, title: "normal") { (action, path) in
        }
        let action2 = UITableViewRowAction.init(style: .Default, title: "default") { (action, path) in
            self.titles.removeAtIndex(0)
            self.tableView?.deleteRowsAtIndexPaths([path], withRowAnimation: .Fade)
        }
        self.actions.insert(action1, atIndex: 0)
        self.actions.insert(action2, atIndex: 1)
    ```
    
  2. 实现代理方法

    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
         return self.actions
    }
    

posted on 2017-01-14 09:55  花老🐯  阅读(168)  评论(0编辑  收藏  举报

导航