gpt4 book ai didi

ios - 如何在 iOS 的 UITableViewCell 上禁用特定方向的滑动?

转载 作者:行者123 更新时间:2023-11-28 22:35:47 26 4
gpt4 key购买 nike

我通过添加以下两种方法在我的 TableView 中实现了滑动删除选项:

- (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
}
}

这很好用,每当我在单元格上滑动时(从左到右和从右到左),一个红色的删除按钮就会很好地出现。

但我只想在用户从右向左滑动时显示删除按钮。当用户从左向右滑动时,我想执行其他操作。能在这里找到方向吗?

最佳答案

只需将滑动手势识别器添加到表格 View 中,以识别您要忽略的方向。

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(emptyMethod:)];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.tableView addGestureRecognizer:swipe];

然后实现 emptyMethod.. 这个方法什么都不做。

- (void)emptyMethod {}

每次您向左滑动时,空方法都会被调用并且什么都不做。

关于ios - 如何在 iOS 的 UITableViewCell 上禁用特定方向的滑动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16104439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com