我在我的表格 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/