Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone中删除表中的一行_Iphone_Objective C_Uitableview - Fatal编程技术网

如何在iPhone中删除表中的一行

如何在iPhone中删除表中的一行,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我有一个UITableView,我想为用户提供当他在行上滑动或轻弹手指时删除行的功能。我知道编辑风格,它提供了一个圆形的红色按钮,上面有-ve符号。但是如何实现flicking样式。我看到很多应用程序都在使用它,所以苹果是否为它提供了内置的代理,或者我们需要为它编写自己的控制器。我几乎肯定有一个示例应用程序可以做到这一点。很快就会有一个更具体的答案 更新:可能正是你想要的 关于主题,以下是提供的最甜蜜的方法之一: // If I want to delete the next 3 cells a

我有一个UITableView,我想为用户提供当他在行上滑动或轻弹手指时删除行的功能。我知道编辑风格,它提供了一个圆形的红色按钮,上面有-ve符号。但是如何实现flicking样式。我看到很多应用程序都在使用它,所以苹果是否为它提供了内置的代理,或者我们需要为它编写自己的控制器。

我几乎肯定有一个示例应用程序可以做到这一点。很快就会有一个更具体的答案

更新:可能正是你想要的

关于主题,以下是提供的最甜蜜的方法之一:

// If I want to delete the next 3 cells after the one you click
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSMutableArray* indexPaths = [NSMutableArray array];
  for (int i = indexPath.row + 3; i < indexPath.row + 3; i++)
  {
    [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
  }

  [tableView beginUpdates];
  [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
  [tableView endUpdates];
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//如果我想删除您单击的单元格之后的下3个单元格
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
NSMutableArray*索引路径=[NSMutableArray];
for(int i=indexPath.row+3;i

我认为有一个更简单的方法来完成你想要的,但这也是非常容易的。唯一的困难可能是删除您自己…请注意SEGFULTS。

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

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
方法,这将提供对滑动交互的访问以进行删除。我通常也会为TableView提供编辑交互,因为滑动交互对用户来说有点隐藏,所以可以删除

例如:

- (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];
}

希望有帮助。

你能告诉我你已经知道的方法吗?因为我想实现它。withRowAnimation:YES是错误的,您应该使用枚举,例如withRowAnimation:UITableViewRowAnimation来考虑更改
…UITableViewRowAnimationTop]
…UITableViewRowAnimationAutomatic]。这是在无效的编辑中完成的(应该是注释),所以我将其还原。如果这是正确的,请考虑相应地更新您的解决方案。那就是我。UITableViewRowAnimationTop应为UITableViewRowAnimationAutomatic,以便在删除时显示正确的动画。