首页 > 解决方案 > 无法告诉用户 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)

            }
        })
    }
}

但我不喜欢那个解决方案——显示模型的警报。有没有标准的方法来告诉这个提交功能失败了?

标签: iosswiftuitableview

解决方案


推荐阅读