Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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 使用EditActionsErrorWatIndeXPath删除一行;UITableView内部错误“;_Ios_Swift_Uitableview_Xcode7 - Fatal编程技术网

Ios 使用EditActionsErrorWatIndeXPath删除一行;UITableView内部错误“;

Ios 使用EditActionsErrorWatIndeXPath删除一行;UITableView内部错误“;,ios,swift,uitableview,xcode7,Ios,Swift,Uitableview,Xcode7,我需要在EditActionsErrorWatIndeXPath中创建一个操作来删除表中的一行。通过互联网上的一些研究,我得出了以下代码: func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { let remove = UITableViewRowAction(style: UITab

我需要在EditActionsErrorWatIndeXPath中创建一个操作来删除表中的一行。通过互联网上的一些研究,我得出了以下代码:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {


        let remove = UITableViewRowAction(style: UITableViewRowActionStyle.Destructive, title: "Remover", handler: { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in
            self.tableData.removeObjectAtIndex(indexPath.row)
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)

        })

        return [remove]
    }
但现在我得到了这个错误

UITableView内部错误:无法使用生成新的分区图 旧节计数:1,新节计数:0


请删除RowsatindExpath或重新加载数据,但不能同时删除两者。

除非您实现自己的自定义附件视图,否则不需要使用“EditActionsFrrowatineXPath”方法,但在其他方面,您可以使用标准的向左滑动手势删除行,并且名为CommittedItingStyle的委托

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        tableData.removeObjectAtIndex(indexPath.row)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    }
    else if editingStyle == .Insert {
        //edit cell
    }
}
//change the default 'Delete' text
override func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
    return "Show this instead of delete"
}

UITableView
删除行时,需要注意两件事

首先,只有在已经从数据源中删除对象之后,才应该调用
tableView.deleteRowsAtIndexPaths
。因为它将再次检查计数,并确保结果数据源的值少一个


现在要记住的第二件事是,删除最后一行后,节的编号不能为0。如果要将0返回到
numberOfSectionsInTableView
,请至少在空行计数时返回1。另一个选项是在删除最后一行时也实际删除索引。

您不需要重新加载表视图同样,错误仍然存在。您使用editAction方法的原因是什么?我使用EditActionsFrrowatinExpath如果我删除第一行a,则收到:是,但是我不能使用boss方法,因为当我不仅有删除功能时,你能解释一下吗?是的,当用户将单元格向左拖动时,他将有两个选项,一个是准备编辑对象,第二个是必须删除此对象,而且必须请求从数据库中删除它。“删除”选项的标题也必须与标准不同。如果要更改标题,还有另一个代表。我会在回答中加上它