区分UITableView编辑状态?

Jos*_*ane 5 iphone objective-c uitableview

我一直在试图区分我的UITableView中的编辑状态.

我需要在点击编辑按钮后仅在编辑模式下调用方法,因此当您将单元格滑入时,您会看到小圆形删除图标,但不是当用户滑动删除时.

无论如何我可以区分这两者吗?

谢谢.

编辑:

解决方案感谢Rodrigo

每个单元格和整个tableview都有一个"编辑"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];            
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Mic*_*chs 5

即使这篇文章很老,以下内容可能对其他人有所帮助:

如果您实现以下委托消息: - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;

编辑单行时将调用这些方法.-[UIViewController setEditing:animated:]然后只有在用户点击编辑按钮时才会被调用.


Rod*_*igo 4

有一种策略,我现在没有测试,但也许可行。

您可以将 UITableView 设置为编辑模式并使用isEditing功能进行测试。但细胞也有同样的isEditing。因此,您可以检查是否只有一个单元格处于编辑状态或所有 UITableView 处于编辑状态。

检查当您将一个单元格设置为编辑状态时,UITableView 是否完全更改为编辑状态。