Tableview swipe 시 기능 추가 (leading, trailing 둘 다 가능)
방법 2가지 >>
1번 방법
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let delete = UIContextualAction(style: .normal, title: "삭제") { [self] action, view, completionHandler in
print("favorite Button Clicked")
repository.delete(item: self.tasks[indexPath.row])
self.fetchRealm()
}
return UISwipeActionsConfiguration(actions: [delete])
}
2번 방법
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == .delete) {
try! localRealm.write {
localRealm.delete(tasks[indexPath.row])
}
tableView.reloadData()
}
}
'iOS > iOS SeSAC 2기 TIL' 카테고리의 다른 글
iOS swift) SceneDelegate 처음 시작화면 지정(with navigation) (0) | 2022.09.03 |
---|---|
2차 평가과제 중 알게된 것들 (테이블뷰 섹션 관련) (0) | 2022.09.02 |
[iOS swift] 오픈소스라이브러리 Panmodal (0) | 2022.09.01 |
iOS swift) Realm SPM으로 설치 (0) | 2022.08.31 |
tableview code로 구현하기 (0) | 2022.08.31 |