ios - 无法告诉用户 UITableViewDatasource 中未删除项目
问题描述
最近我将我的 UITableView 的模型部分分离为 UITableViewDataSource 实现(这个实现是单独的类)。虽然可以删除表的记录,但也必须在 REST API 中进行删除。是否有任何选项如何告诉用户记录没有被删除,eq。发生网络错误?
我可以做这样的事情(在 UITableViewDataSource 的实现中:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
let item = getItem(indexPath)
restApi.delete(item.id, callback: { ok in
if (ok) {
tableView.reloadData()
} else {
let alert = UIAlertController(title: "Warning", message: "Deletion was not successfull.", preferredStyle: .alert)
let okAction: UIAlertAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(okAction)
tableView.superview.present(alert, animated: true, completion: nil)
}
})
}
}
但我不喜欢那个解决方案——显示模型的警报。有没有标准的方法来告诉这个提交功能失败了?
解决方案
推荐阅读
- python - Python 数组 rows*1column numpy for numpy.dot(matrix,matrix2)
- javascript - React 组件无法读取未定义的属性
- python - 在 Raspbian 上手动安装 Python 库
- azure - Sql Server 中是否有办法查找视图中的哪些列未编入索引
- intellij-idea - 不要在 PhpStorm 中封装 else ifs
- mercurial - 查找更改 TortoiseHg 中特定文件的所有提交
- php - Laravel 5.6 - 更新唯一属性
- css - asp.net core Angular Template如何添加site.css
- javascript - 为什么在 process.env 上定义属性会导致奇怪的条件分支?
- ios - 使用单个推送动画推送和呈现视图控制器