编辑模式后UITableViewCell刷新问题
问题描述:
我已经实现了UITableViewCell
的一个子类,名为UITableViewCellCustom
。当进入编辑模式或当我滑动单元格以显示删除按钮时,我想隐藏单元格中的标签,并在退出编辑模式时显示它。编辑模式后UITableViewCell刷新问题
我在UITableViewCellCustom
- (void)willTransitionToState:(UITableViewCellStateMask)state {
[super willTransitionToState:state];
if ((state == UITableViewCellStateShowingDeleteConfirmationMask) || (state == UITableViewCellStateShowingEditControlMask)) {
[UIView animateWithDuration:0.5
animations:^{rankLabel.alpha = 0.0;}];
}
}
- (void)didTransitionToState:(UITableViewCellStateMask)state {
[super didTransitionToState:state];
if (state == UITableViewCellStateDefaultMask) {
[UIView animateWithDuration:0.5
animations:^{rankLabel.alpha = 1.0;}];
}
}
执行下面的代码,我有两个问题。
例如,如果我有我的tableview 23行。当我的前5行显示时,我进入编辑模式。我的rankLabel是隐藏的,然后我滚动到我的桌子底部(到第23行),我退出编辑模式。 rankLabel会再次显示,但不会显示所有单元格,我的单元格6/12和18未正确刷新。任何想法?
在方法
willTransitionToState
我使用animateWithDuration
轻轻隐藏我的rankLabel,但它不起作用,rankLabel隐藏但没有过渡。当我想再次显示标签时,同样的方法在didTransitionToState
中效果很好。任何想法?
感谢您的支持。
答
#2:
- (void)willTransitionToState:(UITableViewCellStateMask)state {
[super willTransitionToState:state];
if ((state == UITableViewCellStateShowingDeleteConfirmationMask) || (state == UITableViewCellStateShowingEditControlMask)) {
[UIView setAnimationsEnabled:TRUE];
[UIView animateWithDuration:0.5
animations:^{rankLabel.alpha = 0.0;}];
}