セルで爪のスワイプの委任方法
-
10-10-2019 - |
質問
テーブルセルを1回スワイプし、削除ボタンが右から入ってくる瞬間と呼ばれる代表的な方法はありますか?
スワイプを追跡し、そこでアクションを実行したかったのです。
また、セル内の「削除」ボタンをタップすると、メソッドが呼び出されます。
解決
UITableViewDelegate
方法 tableView:editingStyleForRowAtIndexPath:
行が「編集」モードに入る前に呼び出されます。これは、セルをスワイプしたときとテーブルビューが受信したときに呼び出されます setEditing:animated
メッセージ。テーブルビューを編集モードにする編集ボタンがある場合は、目に見える各セルに対して呼び出されることに注意する必要があります。
だからあなたは次のようなことをすることができます:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView.editing) {
return UITableViewCellEditingStyleDelete;
}
else {
// do your thing
return UITableViewCellEditingStyleDelete;
}
}
削除]ボタンをタップするとき tableView:commitEditingStyle:forRowAtIndexPath:
呼び出されます。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// repsond to delete
}
}
削除ボタンのテキストを変更する場合は、使用できます tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:
反対側に削除ボタンを表示したくないが、他の何かを実行する場合は、調べる必要があります UISwipeGestureRecognizer
そして、あなた自身を扱います。
所属していません StackOverflow