确定单元格的当前状态 [英] Determining the current state of a cell

查看:135
本文介绍了确定单元格的当前状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 UITableViewCell 的子类可以实现 willTransitionToState 并在转换时执行自定义代码。但是有没有办法找到一个单元格的当前状态?

I know that a subclass of UITableViewCell can implement willTransitionToState and execute custom code at the time of transition. But is there any way to find the current state of a cell?

如果没有,我应该子类 UITableViewCell 定义一个属性 currentState ,我总是更新在 willTransitionToState ?我会总是有办法知道任何特定细胞的状态。

If not, should I subclass UITableViewCell and define a property currentState, which I always update in my willTransitionToState? I will then always have a way to know the state of any particular cell.

似乎很奇怪,我不能问单元格它的当前状态是(0,1 ,2或3)。

Seems strange that I can't ask a cell what its current state is (0, 1, 2, or 3).

推荐答案

当前状态为 UITableViewCellStateDefaultMask (0), UITableViewCellStateShowingEditControlMask (1), UITableViewCellStateShowingDeleteConfirmationMask (2)和 UITableViewCellStateShowingEditControlMask | UITableViewCellStateShowingDeleteConfirmationMask (3)。

The current states are UITableViewCellStateDefaultMask (0), UITableViewCellStateShowingEditControlMask (1), UITableViewCellStateShowingDeleteConfirmationMask (2), and UITableViewCellStateShowingEditControlMask | UITableViewCellStateShowingDeleteConfirmationMask (3).

这些状态对应于属性的值editing showingDeleteConfirmation 。它可以如下测试:

These states correspond to the values of the properties editing and showingDeleteConfirmation. It can be tested as follows:

if (!cell.editing && !cell.showingDeleteConfirmation) {
    // 0 - UITableViewCellStateDefaultMask
} else if (cell.editing && !cell.showingDeleteConfirmation) {
    // 1 - UITableViewCellStateShowingEditControlMask
} else if (!cell.editing && cell.showingDeleteConfirmation) {
    // 2 - UITableViewCellStateShowingDeleteConfirmationMask
} else if (cell.editing && cell.showingDeleteConfirmation) {
    // 3 - UITableViewCellStateShowingEditControlMask | UITableViewCellStateShowingDeleteConfirmationMask
}

这篇关于确定单元格的当前状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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