区分UITableView编辑状态? [英] Differentiate Between UITableView Editing States?

查看:53
本文介绍了区分UITableView编辑状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been looking at trying to differentiate between editing states in my UITableView.

我只需要在点击编辑按钮后处于编辑模式时才调用一种方法,因此当您插入单元格幻灯片时,您会看到圆形的小删除图标,而在用户滑动以删除时则不需要.

I need to call a method only when in editing mode after tapping the edit button, so when you get your cell slide in and you see the little circular delete icons but NOT when the user swipes to delete.

反正我能区分两者吗?

谢谢.

感谢Rodrigo的解决方案

Solution thanks to Rodrigo

每个单元格和整个表视图都有一个正在编辑"的BOOL值,因此我遍历所有单元格,如果其中多个单元格正在编辑,则我们知道整个表都是(用户点按了编辑"按钮),但是,如果只有一个正在编辑,则我们知道用户已刷了一个单元格,正在编辑单个单元格,这使我可以分别处理每个编辑状态!

Both each cell and the entire tableview has an 'editing' BOOL value, so I loop through all the cells and if more than one of them is editing then we know the whole table is (the user tapped the edit button), however if only one is editing then we know that the user has swiped a cell, editing that individual one, this lets me deal with each editing state individually!

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

推荐答案

有一种策略,我现在不测试,但也许可以.

There are one strategy, I do not test now, but maybe work.

您可以将UITableView设置为处于编辑模式,并使用isEditing功能进行测试.但是单元格具有相同的isEditing.因此,您可以检查是只有一个单元格处于编辑状态还是所有UITableView.

You can set the UITableView to be in editing mode and test with isEditing function. But the cell have the same isEditing. So you can check if only one cell is in editing state or all the UITableView.

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

Check if when you set one cell to be in editing state, the UITableView change to editing state at all.

这篇关于区分UITableView编辑状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆