iOS) UITalbeViewCell SwipeAction

less than 1 minute read

UITalbeViewCell SwipeAction

UITableViewDatasource - trailingSwipeActionConfigurationForRowAt

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    //info
    let info = UIContextualAction(style: .normal, title: "세부사항") { action, view, completion in
    //세부사항을 클릭하면 모달창을 띄우게 함.
        guard let nextVC = self.storyboard?.instantiateViewController(identifier: DetailReminderVC.identifier) as? DetailReminderVC else {
                return
            }
        //modally
        self.present(nextVC, animated: true, completion: nil)
    }
    //delete 
    let delete = UIContextualAction(style: .destructive, title: "삭제") { action, view, completion in
    //tableContents 라는 배열에 정보를 저장했다.
        self.tableContents.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .automatic)
    }

    return UISwipeActionsConfiguration(actions: [delete, info])
}

Categories:

Updated: