【问题标题】:Reverting UITableViewCell to normal editing mode将 UITableViewCell 恢复为正常编辑模式
【发布时间】:2012-05-05 15:39:14
【问题描述】:

当用户决定删除 UITableViewCell 时,会出现第二个确认对话框。这是我正常状态下的表格视图:


这是整个表格进入编辑模式的时候:


现在,当用户点击左侧的红色减号之一时,单元格将进入删除确认模式:


如果用户随后点击刚刚出现的删除按钮,则会出现此操作表:


这就是问题出现的地方。如果用户确认他们要删除地图,一切都很好。但是如果按下取消按钮,操作表就会消失,但表格视图仍然是这样的:

问题是删除确认按钮不应再处于其选定状态,并且应该隐藏自身。正如你所看到的,它没有。我在文档中的搜索已经结束,没有结果。我不想setEditing:NO,因为我希望表格保持正常的编辑状态。有什么想法吗?

编辑1:这是tableView:commitEditingStyle:forRowAtIndexPath:内部发生的事情

- (void)tableView:(UITableView*)tableView commitEditingStyle:
    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
    NSInteger finalIndex = [self getFinalIndexForIndexPath:indexPath];

    NSString* mapTitle = ((PreviewDataObject*)[[[SingletonDataController sharedSingleton]
        getImportedOrSavedMapPreviews:masterIdentifierString] 
        objectAtIndex:finalIndex]).titleString;

    UIActionSheetWithIndexPath* sheet = [[UIActionSheetWithIndexPath alloc] initWithTitle:
        [NSString stringWithFormat:@"Are you sure you want to delete the map '%@'?", 
        mapTitle] delegate:self cancelButtonTitle:@"Cancel" 
        destructiveButtonTitle:@"Delete Map" otherButtonTitles:nil];
    sheet.indexPath = indexPath;
    [sheet showFromTabBar:[AppDelegate appDelegate].tabBarController.tabBar];
    [sheet release];
}

【问题讨论】:

  • 你可以显示代码 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  • 你能告诉我们你的数组名称是什么吗?
  • commitEditingStyle,我实际上并没有做任何删除;我只是展示了提示用户是否真的想要删除地图的操作表。

标签: ios user-interface uitableview editing


【解决方案1】:

之后,您还可以显示一个 AlertView,询问他们是否真的、真的、真的想要删除。

打开按钮然后按删除的两步过程应该是足够的确认。

在我看来,做你正在做的事情并不是标准做法,一旦你进入那个领域,你就会发现框架中的漏洞。

【讨论】:

  • 我想你可能是对的,尽管我仍然希望有一种方法可以做我想做的事。
  • 我认为@eric.mitchell 试图完成的事情是合理的。尽管如此,这个答案让我真的笑了:)。有一种简单的方法可以完成您的要求,请参阅我的答案。虽然晚了 4 年...
【解决方案2】:

我同意上面的讨论,需要点击删除 3 次是个坏主意。

但是,对于其他操作,可能有充分的理由重置该行。最简单的解决方案就是重新加载那一行。

斯威夫特 2.2:

tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)

【讨论】:

    【解决方案3】:

    试试这个,告诉我它是否适合你。

      -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
      {
          if (editingStyle == UITableViewCellEditingStyleDelete)
           {
               // Delete the row from the data source.
    
               [arr removeObjectAtIndex:indexPath.row];
    
    
               [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
             }
            else if (editingStyle == UITableViewCellEditingStyleInsert)
            {
              // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
            }   
        }
    

    【讨论】:

      【解决方案4】:

      直接退出编辑模式(Swift):

      tableView.setEditing(false, animated: true)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多