在iOS 7中取消UITableViewCell滑动删除时收到通知

时间:2013-09-26 19:13:14

标签: iphone uitableview ios7 hidden

我正在使用willTransitionToState,当显示右手删除按钮时会通知我。但是,通过点击单元格区域外部取消删除时,不会调用此方法。我也尝试了tableView:didEndEditingRowAtIndexPath。

this问题中的答案在iOS 7中无效。

1 个答案:

答案 0 :(得分:0)

以下代码适用于iOS 7(不适用于iOS 6)。 iOS 6解决方案是this

- (void)layoutSubviews
{
    [super layoutSubviews];

    [self detectDeleteButtonState];

    // it takes some time for delete button to disappear
    [self performSelector:@selector(detectDeleteButtonState) withObject:self afterDelay:1.0]; 
}

- (void)detectDeleteButtonState
{
    BOOL isDeleteButtonPresent = [self isDeleteButtonPresent:self.subviews];
    if (isDeleteButtonPresent) {
        NSLog(@"delete button is shown");
    } else {
        NSLog(@"delete button is gone");
    }
}

-(BOOL)isDeleteButtonPresent:(NSArray*)subviews
{
    for (UIView *subview in subviews)
    {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"])
        {
           return [subview isHidden] == NO;
        }
        if([subview.subviews count] > 0){
           return [self isDeleteButtonPresent:subview.subviews];
        }
    }

    return NO;
}