Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.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
Ios 当用户使用滑动手势编辑UITableViewCellEditingStyleDelete模式时,如何离开该模式_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 当用户使用滑动手势编辑UITableViewCellEditingStyleDelete模式时,如何离开该模式

Ios 当用户使用滑动手势编辑UITableViewCellEditingStyleDelete模式时,如何离开该模式,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我需要在用户点击删除按钮后离开删除模式。我想显示一些活动指示器,并等待服务器对删除操作的响应,然后再实际删除单元格(如果服务器没有响应,则不会)。我要从委托方法执行的此操作: - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 我该怎么做呢?在我的代码中,

我需要在用户点击删除按钮后离开删除模式。我想显示一些活动指示器,并等待服务器对删除操作的响应,然后再实际删除单元格(如果服务器没有响应,则不会)。我要从委托方法执行的此操作:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

我该怎么做呢?

在我的代码中,我向

[self.tableView重载数据]

我不确定这是否是100%正确的方法,但它对我有效。所以你的函数可以是这样的:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Do your processing.

[self.tableView reloadData];

}
然后它应该清除红色的删除按钮并刷新数据

你也可以玩转这个电话

[tableView deleteRowsAtIndexPaths:@[indexPath]带RowAnimation:UITableViewRowAnimationFade]


但根据我的经验,在我的代码中,调用重载数据似乎起到了关键作用

[self.tableView重载数据]

我不确定这是否是100%正确的方法,但它对我有效。所以你的函数可以是这样的:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Do your processing.

[self.tableView reloadData];

}
然后它应该清除红色的删除按钮并刷新数据

你也可以玩转这个电话

[tableView deleteRowsAtIndexPaths:@[indexPath]带RowAnimation:UITableViewRowAnimationFade]

但根据我的经验,
reloadData
调用似乎起到了隐藏“Delete”按钮的作用,您需要使用
setEditing:animated:
方法

但是,
tableView:committeeditingstyle:forRowAtIndexPath:
的实现需要稍微延迟执行。图7-1下方参考中的注释说明:

注意:数据源不应在其tableView:CommittedItingStyle:forRowAtIndexPath:的实现中调用setEditing:animated:。如果出于某种原因,它必须在延迟后使用performSelector:withObject:afterDelay:方法调用它

因此,您的实现可以如下所示:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // remove delete button only after short delay
        [self performSelector:@selector(hideDeleteButton:) withObject:nil afterDelay:0.1];
    }
}

- (void)hideDeleteButton:(id)obj
{
    [self.tableView setEditing:NO animated:YES];
}
当用户按下删除按钮时,上面的代码使其在0.1秒后滑开。当然,在等待操作完成时,您需要防止它返回到编辑模式。为此,您可以覆盖UITableViewDataSource方法
tableView:CaneditRowatineXpath:
,以防止在等待时再次编辑同一单元格或整个表格。

要隐藏“删除”按钮,您需要使用
setEditing:animated:
方法

但是,
tableView:committeeditingstyle:forRowAtIndexPath:
的实现需要稍微延迟执行。图7-1下方参考中的注释说明:

注意:数据源不应在其tableView:CommittedItingStyle:forRowAtIndexPath:的实现中调用setEditing:animated:。如果出于某种原因,它必须在延迟后使用performSelector:withObject:afterDelay:方法调用它

因此,您的实现可以如下所示:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // remove delete button only after short delay
        [self performSelector:@selector(hideDeleteButton:) withObject:nil afterDelay:0.1];
    }
}

- (void)hideDeleteButton:(id)obj
{
    [self.tableView setEditing:NO animated:YES];
}

当用户按下删除按钮时,上面的代码使其在0.1秒后滑开。当然,在等待操作完成时,您需要防止它返回到编辑模式。为此,,您可以重写UITableViewDataSource方法
tableView:CaneditRowatineXpath:
,以防止在等待时再次编辑同一单元格或整个表。

您好,让我直截了当地说:您的数据源实际上处于联机状态,您希望在更新tableView之前确认它已被删除-同时要显示AI活动指示器

如果这就是你想要做的,那么你就从这个方法开始

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
 // Get the key of the data you want to delete.

 data_struct_instance * data =  [self.mutableArray_data_source objectForRowAtIndexPath:indexPath];
 NSString *data_key = data.key;
 row_index = indexPath.row;  //   set a property to preserve the row (or index path for multilevel data) for use when you delete the the record later.

 [self start_UIActivityIndicator];
 [self callonline_with_delete_command:data_key]; //  send the request to delete the record

  }
一旦服务器根据是否成功做出响应,您可以删除记录或重新加载整个数组(如果表很小),最好确保数据同步-

 ....  
    [activityindicator StopAnimating];

   if (success) {

     [self.mutableArray_data_source removeObjectAtIndex:row_index];}
  else {
       NSLog .... 
         }

   [self.tableView reloadData];  // resets the delete button. 

嗨,让我直截了当地说:你的数据源实际上是在线的,你需要在更新tableview之前确认它已被删除——同时你还需要显示AI活动指示器

如果这就是你想要做的,那么你就从这个方法开始

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
 // Get the key of the data you want to delete.

 data_struct_instance * data =  [self.mutableArray_data_source objectForRowAtIndexPath:indexPath];
 NSString *data_key = data.key;
 row_index = indexPath.row;  //   set a property to preserve the row (or index path for multilevel data) for use when you delete the the record later.

 [self start_UIActivityIndicator];
 [self callonline_with_delete_command:data_key]; //  send the request to delete the record

  }
一旦服务器根据是否成功做出响应,您可以删除记录或重新加载整个数组(如果表很小),最好确保数据同步-

 ....  
    [activityindicator StopAnimating];

   if (success) {

     [self.mutableArray_data_source removeObjectAtIndex:row_index];}
  else {
       NSLog .... 
         }

   [self.tableView reloadData];  // resets the delete button. 

签入didFinishLoading并重新加载表…签入didFinishLoading并重新加载表…它可以工作,但我想在将第二个答案标记为正确之前检查第二个答案,您选择了哪一个?重新加载整个表视图对我来说不是最好的方案。我不明白你说的第二句话是什么意思,因为我不想真的删除单元格,我想让它保留下来,并在上面显示活动指示器。它可以工作,但我想检查第二个答案,然后再将其中一个标记为正确,你选择了哪一个?重新加载整个表视图对我来说不是最好的方案。我不明白你们说的第二句话是什么意思,因为我不想真的把电池移走,我想让它留下来,并在上面显示活动指示器。是的,你们说的差不多对了。但我想立即删除删除按钮,并在单元格顶部显示活动指示器,以显示正在进行的操作,并允许用户继续浏览列表是的,您的操作几乎正确。但我想立即删除“删除”按钮,并在单元格顶部显示“活动指示器”,以显示正在进行的操作,并允许用户继续浏览列表。这很好,不需要重新加载表,所以我选择了那个。实际上,我以前尝试过
performSelector:
setEditing:
方法,但它不起作用,现在不起作用。这很好,不需要重新加载表,所以我选择了那个方法。实际上我尝试了
performSelector:
setEditing:
meth