ios - 如何知道是否使用 MGSwipeTableCell 删除了所有单元格

标签 ios objective-c uitableview

我在我的表格 View 中使用 MGSwipeTableViewCell 通过在显示删除按钮的单元格上滑动并按下它来删除行,使用这个库来删除或删除单元格。我的问题是,当所有单元格都被删除时,表格 View 消失了,我的 View 布局也被打乱了。所以我想在我通过滑动删除所有单元格时收到通知,这样我就可以应用或更新约束来管理 View 的布局。

最佳答案

您应该使用以下委托(delegate)方法,在这里您可以检查删除特定单元格后还剩下多少行,并根据要求更新约束。

-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell tappedButtonAtIndex:(NSInteger) index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion
{
      NSLog(@"Delegate: button tapped, %@ position, index %d, from Expansion: %@",


    if (direction == MGSwipeDirectionRightToLeft && index == 0) {
    //delete button is tapped or full swiped
        NSIndexPath * path = [_tableView indexPathForCell:cell];
        [tests removeObjectAtIndex:path.row];
        [_tableView deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationLeft];
        return NO; //Don't autohide to improve delete expansion animation
    }

    return YES;
}

来源:MGSwipeDemo示例代码

关于ios - 如何知道是否使用 MGSwipeTableCell 删除了所有单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38605225/

相关文章:

ios - UIRefreshControl - 在 iOS 7 中拉动刷新

ios - 为什么我的 iOS 构建在处理后从 iTunes Connect 构建部分中删除?

ios - 将 UIPanGestureRecognizer 和 UISwipeGestureRecognizer 添加到同一 View 会导致在设置 requireGestureToFail 后发生冲突

python - C 或 Python 中的 NSScanner 等效项

ios - 具有自动布局约束的 UITableViewCell 子类大小不正确

ios - 创建一个可扩展的 UITableView

ios - 使用 scrollViewDidScroll 移动 ChildViewController 的 subview

ios - 如何在 UIStackView 中排列的 subview 上设置自定义高度?

ios - 对多个 iBeacon 使用react

ios - "display: flex"和 "align-items: center"怎么可能在我的 iphone 上不再工作了?