3

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

在这个问题中找到的答案在 iOS 7 中不起作用。

4

1 回答 1

0

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

- (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;
}
于 2013-11-08T07:34:08.377 回答