让UITableViewCell显示没有红色减号的删除按钮

时间:2013-04-24 08:51:05

标签: ios objective-c uitableview

我想实现一个UITableView当我按下ViewController中的按钮时,我可以看到单元格右侧的删除按钮,但不能看到左侧的红色减号圆圈细胞。

有关于此的任何想法吗?

5 个答案:

答案 0 :(得分:3)

只是一种方法:

  1. 在视图上设置删除按钮并为其指定方法
  2. 在此方法中,将BOOL isDeleteEnabled(或您命名的任何内容)切换为TRUE
  3. 重新加载UITableView并在cellForRowAtIndexPath中检查该BOOL值
  4. 如果TRUE,则将所有UITableViewCell加载为自定义单元格 使用删除按钮(您需要设置选择器方法) 删除一行)
  5. 点击单元格上的按钮
  6. ,删除任意数量的单元格
  7. 删除您的选择后,您可以再次按主按钮和 切换isDeleteEnabled
  8. 的值
  9. 再次重新加载UITableView,这次是cellForRowAtIndexPath 检查isDeleteEnabled的值 - FALSE。因此,您需要加载普通(或原始)UITableViewCells。
  10. 我按照这种方法做了非常相似的事情。

    此外,我还没有发布代码,原因有三个:

    • 大小太长
    • 他在我的工作机器上可用的代码(我没有 现在访问)
    • 它会毁掉编写这样一个任务的快乐。自己做。你会 请它。

答案 1 :(得分:1)

如果您不希望出现减号,那么请考虑实现您自己的解决方案而不是默认解决方案,插入删除按钮并为其提供动画,根据需要执行

答案 2 :(得分:-2)

您不需要按钮操作来触发此操作。如果您实现以下委托,则可以直接滑动并删除单元格。

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
    {
   //Delete the row
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

答案 3 :(得分:-2)

我的想法,不要使用按钮,但你可以使用以下方法滑动要删除的单元格:

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

    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
         //Use actionsheet or deleteRowsAtIndexPaths
    }

 }

答案 4 :(得分:-3)

覆盖以支持编辑表格视图。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete
    }    
}