UITableView
編集用に 2 つのオプションを実装したいと思います。
1.ユーザーがスワイプするUITableViewCell
と、 が表示されますUITableViewCellEditingStyleDelete
。
2.ユーザーが編集ボタンを押すと、編集モードに入ります( .mファイルUITableView
で自分で定義します:UITableViewCell
-(void) setEditing:(BOOL)editing animated:(BOOL)animated {
if ( (selectionButton.superview == self.contentView && !editing) || (selectionButton.superview != self && editing))
{
// REMOVE BUTTON
[super setEditing:editing animated:animated];
if (self.editingStyle != UITableViewCellEditingStyleDelete) {
if (!editing)
{
if (selectionButton.superview == self.contentView)
{
[UIView animateWithDuration:0.5 animations:^
{
selectionButton.alpha = 0;
CGRect btnFrame = selectionButton.frame;
btnFrame.origin.x -= 120;
selectionButton.frame = btnFrame;
}
completion: ^(BOOL done)
{
[selectionButton removeFromSuperview];
}
];
}
}
else {
// ADD BUTTON
if (selectionButton.superview != self.contentView)
{
[self.contentView addSubview:selectionButton];
selectionButton.alpha = 0;
selectionButton.center = CGPointMake(-self.contentView.frame.origin.x / 2 - 30, self.frame.size.height / 2);
[UIView animateWithDuration:0.3 animations:^
{
selectionButton.alpha = 1;
selectionButton.center = CGPointMake(-self.contentView.frame.origin.x / 2 + 3, self.frame.size.height / 2);
}];
}
}
[self setNeedsLayout];
}
}
}
このデリゲート メソッドを my に追加したいUITableView
:
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (table.editing) {
return 3;
} else {
return UITableViewCellEditingStyleDelete;
}
// return 3;
}
しかし、問題は、セルを指でスワイプすると関数が 3 回呼び出されることです。
それを修正する方法はありますか?またはUITableView
、ユーザーがスワイプしたときにこのメソッドが呼び出されたセルに組み込まれていますか?
独自に実装してUISwipeGestureRecognizer
、編集ボタンを押したときにのみデリゲート関数を呼び出すことはできますか?