【发布时间】:2018-05-30 04:09:25
【问题描述】:
我正在开发一个带有 Firebase 数据库的应用,我还希望允许用户在离线时添加条目。想象一下以下情况(一切都离线;它可以在线完美运行):
- 用户添加了一个客户端(显示在主表视图中 - 有效)
- 在新添加的客户的详细视图中,他添加了与他的约会。约会在 Client Detail ViewController 的 tableview 中列出。
- 添加约会时,tableview 不会刷新,因为回调没有调用。
在代码中:
-
navCont.child = userDB.child(entityNameClients).childByAutoId() navCont.child?.setValue(post)其中 post 是包含客户值的字典 - 在detail view controller的viewDidLoad方法上,我调用如下代码:
getUsersDBReference().child(entityNameAppointments).child(clientKey).observe(.value)。未调用回调(可能是因为其中没有元素) -
添加预约
var appointment:DatabaseReferenceappointment = getUsersDBReference().child(entityNameAppointments).child(clientKey).childByAutoId() appointment.setValue(appointmentDict) 未调用 2 的回调(--> 并且 tableview 未使用新约会刷新)
顺便说一句,我在 App Delegates applicationDidLoad-method 中设置了 Database.database().isPersistenceEnabled = true。
如果我在线添加客户端然后离线,它也可以工作。
【问题讨论】:
标签: ios swift firebase firebase-realtime-database offline