2016-07-27 56 views
0

我在我的表格视图中使用MGSwipeTableViewCell通过在单元格上滑动来删除行,该单元格显示删除按钮并按下它,使用此库获取单元格删除或删除。我的问题是,当所有的单元格被删除时,表格视图消失,我的视图布局受到干扰。所以我希望在通过滑动删除所有单元格时得到通知,这样我就可以应用或更新约束来管理视图的布局。如何知道是否所有单元格使用MGSwipeTableCell删除

回答

1

您应该使用下面的委托方法,在这里您可以检查在删除特定单元格并根据需求更新您的约束后剩下的行数。

-(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示例代码

0

当你后,删除你的细胞,你可以通知有多少剩余的细胞通过使用这个属性在你的表视图中可见。 NSLog(@“Remaining visible cells =%lu”,(unsigned long)_table.visibleCells.count);

所以通过使用这段代码,当没有。的单元格将为零,那么你可以处理你的要求。

[_table deleteRowsAtIndexPaths:@[[_table indexPathForCell:btn]] withRowAnimation:UITableViewRowAnimationFade]; 
NSLog(@"Remaining visible cells = %lu",(unsigned long)_table.visibleCells.count); 
if (_table.visibleCells.count==0) { 
    [[[UIAlertView new] initWithTitle:nil message:@"All record deleted" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] show]; 
} 
相关问题