【问题标题】:Suppress UITableViewCell delete button when using overriden setEditing method on iOS 7在 iOS 7 上使用覆盖的 setEditing 方法时禁止 UITableViewCell 删除按钮
【发布时间】:2014-01-15 16:14:53
【问题描述】:

我有几个 UITableViewCell 子类,它们覆盖了 - (void)setEditing:(BOOL)editing animated:(BOOL)animated 方法。在我的实现中,当单元格被滑动时,我有动画来显示和隐藏自定义视图。在 iOS 6 上,这可以完美运行。我的自定义视图是动画的,并且没有显示默认的删除按钮。然而,在 iOS 7 上,我得到了我的自定义视图和动画以及默认的删除按钮。我正在努力寻找一种方法来使用我被覆盖的setEditing:animated:,而无需获得系统删除按钮。

在我的 UITableViewCell 子类中,我已经像这样覆盖了setEditing:animated:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    if (editing) {
        CGFloat buttonWidth = _editButton.frame.size.width;
        [UIView animateWithDuration:0.3
                              delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                         animations: ^{
                             [_shareButtonXConst setConstant:buttonWidth * -3.0];
                             [self layoutIfNeeded];
                         }
                         completion:nil];
    } else {
        [UIView animateWithDuration:0.3
                              delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                         animations: ^{
                             [_shareButtonXConst setConstant:0.0];
                             [self layoutIfNeeded];
                         }
                         completion:nil];
    }
}

在我的 UIViewController 我有:

- (void)loadView
{
    // ...

    UITableView *tableView = [[UITableView alloc] init];
    _tableView = tableView;
    [_tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [_tableView setBackgroundColor:[UIColor clearColor]];
    [_tableView setRowHeight:80.0];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];

    // ...
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

我已经对此进行了相当多的修改,并且在我滑动时无法阻止删除按钮出现。有没有其他人遇到过这个问题?谢谢!

【问题讨论】:

    标签: ios ios7


    【解决方案1】:

    如果您不想要删除按钮,则应在 editingStyleForRow... 数据源方法中返回 UITableViewCellEditingStyleNone

    【讨论】:

    • 感谢您的回复。但是,我在这里测试了返回这个UITableViewCellEditingStyleNone,当我在一个单元格上滑动时它根本不会发生任何事情。我没有得到删除按钮或我的自定义动画。 iOS 6 和 7 也是如此。
    • 将您自己的滑动手势识别器添加到您的单元格中。
    • 我试图避免这种情况,但不应该这么懒惰。我添加了自己的手势识别器,一切正常。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-02
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多