[英]How to disable swipe in particular direction on UITableViewCell in iOS?
I have implemented swipe-to-delete option in my table view by adding the following two methods: 我通过添加以下两种方法在表视图中实现了“滑动到删除”选项:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
//Action to delete
}
}
This working well, and whenever I swipe on the cells (both left-to-right and right-to-left), a red color delete button appears well. 这很好用,每当我在单元格上滑动时(从左到右和从右到左),红色删除按钮就会出现。
But I want to show the delete button only if, the user swipes from right-to-left direction. 但是我想只显示删除按钮,用户从右向左滑动。 When the user swipes in left-to-right, I want to perform someother actions.
当用户从左向右滑动时,我想执行其他一些操作。 Is it possible to findout the direction here?
有可能在这里找到方向吗?
Just add a swipe gesture recognizer to the table view for the direction you want to ignore. 只需在表格视图中添加滑动手势识别器,即可忽略您想要的方向。
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(emptyMethod:)];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.tableView addGestureRecognizer:swipe];
Then implement the emptyMethod.. this method won't do anything. 然后实现emptyMethod ..这个方法不会做任何事情。
- (void)emptyMethod {}
Everytime you swipe left, the empty method will be called and does.. nothing. 每次向左滑动时,都会调用空方法并且没有任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.