테이블뷰 셀 스와이프해서 삭제하기

기본 처리

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        array.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)
    }
}

버튼 문자 및 배경색 변경처리

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

    let deleteButton: UITableViewRowAction = UITableViewRowAction(style: .normal, title: "삭제") { (action, index) -> Void in
        self.array.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)

        //delete 서버 함수 호출

    }
    deleteButton.backgroundColor = UIColor.red

    return [deleteButton]
}

results matching ""

    No results matching ""