我一直在尝试区分 UITableView 中的编辑状态。
我只需要在点击编辑按钮后处于编辑模式时调用一个方法,因此当您滑入单元格时,您会看到小圆形删除图标,但当用户滑动删除时则不会。
无论如何我可以区分两者吗?
Thanks.
EDIT:
感谢罗德里戈的解决方案
每个单元格和整个表格视图都有一个“编辑”BOOL 值,因此我循环遍历所有单元格,如果其中多个单元格正在编辑,那么我们就知道整个表格正在编辑(用户点击了编辑按钮),但是如果只有一个正在编辑,然后我们知道用户已经滑动了一个单元格,编辑那个单独的单元格,这让我可以单独处理每个编辑状态!
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
int i = 0;
//When editing loop through cells and hide status image so it doesn't block delete controls. Fade back in when done editing.
for (customGuestCell *cell in self.tableView.visibleCells)
{
if (cell.isEditing) {
i += 1;
}
}
if (i > 1)
{
for (customGuestCell *cell in self.tableView.visibleCells)
{
if (editing)
{
// loop through the visible cells and animate their imageViews
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
cell.statusImg.alpha = 0;
[UIView commitAnimations];
}
}
}
else if (!editing)
{
for (customGuestCell *cell in self.tableView.visibleCells)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
cell.statusImg.alpha = 1.0;
[UIView commitAnimations];
}
}
}
即使这篇文章很旧,以下内容也可能对其他人有所帮助:
如果您实现以下委托消息:- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
and
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;
编辑单行时将调用这些方法。-[UIViewController setEditing:animated:]
只有当用户点击编辑按钮时才会被调用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)