gpt4 book ai didi

ios - 检测滑动删除按钮和在编辑模式下制作的删除按钮之间的区别?

转载 作者:可可西里 更新时间:2023-11-01 06:23:18 24 4
gpt4 key购买 nike

我目前设置了一个 UITableView 以启用滑动删除(滑动显示删除按钮)。我还有一个编辑按钮,当按下该按钮时,它会在每个单元格的红色删除圆圈中滑动。点击其中一个圆圈会导致删除按钮显示,就好像我滑动了单元格一样。

我想检测删除按钮是通过红色圆圈之一创建的(即在编辑模式下)还是通过直接在单元格上滑动创建的(原因是我希望用户确认他们是否没有通过编辑模式进入,因为如果误操作,他们可能会丢失大量数据)。

我已经尝试了 tableView 的 isEditing 属性,但这是 YES 但是我得到了删除按钮。是否有更细微的方法来检测这一点?

提前致谢!

最佳答案

更简单的方法是使用 UITableView 委托(delegate)支持来了解您何时将要进入单行编辑。 tableView:willBeginEditingRowAtIndexPath: 委托(delegate)调用发生在调用 setEditing:animated: 之前,它允许您避免任何正常的编辑设置,例如创建插入行等。 tableView:willEndEditingRowAtIndexPath: 在 setEditing:animated 之后调用。

所以代码很简单:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.singleRowDeleteMode = YES;
}

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.singleRowDeleteMode = NO;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
if (self.singleRowDeleteMode) { return; }
// Continue setup of normal edit mode
}

关于ios - 检测滑动删除按钮和在编辑模式下制作的删除按钮之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20046822/

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