Created
February 6, 2020 07:50
-
-
Save M-Miyazako/81a54d334237e9288688ccf9d1d56463 to your computer and use it in GitHub Desktop.
# 削除可能なテーブルセル 要RxSwift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import UIKit | |
/// セルの削除が可能なプロトコル | |
protocol CellRemovable: class { | |
var cellRemovedSubject: PublishSubject<Int> { get } | |
func removeConfiguration(at indexPath: IndexPath) -> UISwipeActionsConfiguration? | |
} | |
extension CellRemovable { | |
func removeConfiguration(at indexPath: IndexPath) -> UISwipeActionsConfiguration? { | |
let delete = UIContextualAction(style: .destructive, title: "削除") { [weak self] (_, _, completionHandler) in | |
do { | |
// TODO | |
completionHandler(true) | |
self?.cellRemovedSubject.onNext(indexPath.row) | |
self?.cellRemovedSubject.onCompleted() | |
} catch { | |
completionHandler(false) | |
} | |
} | |
let swipeAction = UISwipeActionsConfiguration(actions: [delete]) | |
swipeAction.performsFirstActionWithFullSwipe = false | |
return swipeAction | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class HogeTableAdapter: UITableViewDelegate, CellRemovable { | |
func tableView(_ tableView: UITableView, | |
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { | |
return removeConfiguration(at: indexPath) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment