天天看點

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