天天看点

swift中tableview给cell添加左划菜单

直接在文件中加入函数就行      
func tableView( tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    //设计左划菜单,添加和打招呼
    let more = UITableViewRowAction(style: .normal, title: "添加") { action, index in
        //第一个按钮点击后操作放这里
    }
    //设置颜色
    more.backgroundColor = UIColor.lightGray

    let favorite = UITableViewRowAction(style: .normal, title: "打招呼") { action, index in
        //第二个按钮操作

    }
    favorite.backgroundColor = UIColor.orange
    //返回两个按钮
    return [favorite, more]
}