2 uitableview ios swift xcode7
我需要在editActionsForRowAtIndexPath中创建一个动作来删除表中的行.在互联网上进行一些研究之后,我来到了这段代码:
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]
}
Run Code Online (Sandbox Code Playgroud)
但现在我收到了这个错误
UITableView内部错误:无法生成具有旧部分计数的新剖面图:1和新部分计数:0
从中删除行时UITableView,需要处理两件事.
首先,tableView.deleteRowsAtIndexPaths只有在从数据源中删除对象后才应该调用.因为它会再次检查计数并确保结果数据源的值减少一个.
现在要记住的第二件事是没有.删除最后一行后,section不能为0.如果要返回0 numberOfSectionsInTableView,则至少在空行数上返回1.另一个选择是在删除最后一行时实际删除索引.
| 归档时间: |
|
| 查看次数: |
1666 次 |
| 最近记录: |