如何在iPhone中删除一行表

rkb*_*rkb 5 iphone objective-c uitableview

我有一个UITableView,我想为用户提供功能,当他在行上滑动或轻弹手指时删除该行.我知道编辑样式,它提供了一个带有-ve标志的圆形红色按钮.但是如何实现轻弹风格.我看到许多应用程序使用它,因此apple为它提供了任何内置委托,或者我们需要为它编写自己的控制器.

pau*_*erd 32

为了获得滑动效果,您需要实现表视图委托

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
Run Code Online (Sandbox Code Playgroud)

方法,这将提供对滑动交互的访问以进行删除.我通常也提供编辑交互以及可以删除的tableviews,因为滑动交互往往对用户有点隐藏.

举个例子:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  [tableView beginUpdates];    
  if (editingStyle == UITableViewCellEditingStyleDelete) {
    // Do whatever data deletion you need to do...
    // Delete the row from the data source
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop];   
  }       
  [tableView endUpdates];
}
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.