【发布时间】:2017-11-29 04:42:59
【问题描述】:
所以我试图让表格单元格在任何其他单元格发生更改时自动刷新。我希望我的代码可以一举找到表格数组中的对象,更改值并刷新表格视图,但是由于某种原因,即使我的数组更新了,表格也拒绝立即更新。要查看我的新值,我必须重新启动应用程序或重新打开视图。
这就是我目前正在做的事情:
usersRef.queryOrdered(byChild "contactList/(currentUID!)").queryEqual(toValue: true).observe(.childChanged, with: { (snapshot) in
if let friends = snapshot.value as? [String: AnyObject] {
//Making a new updated contact
let name = friends["name"] as! String
print(name)
let edit = Contact()
edit.name = name;
edit.isSafe = friends["isSafe"] as! Bool
edit.email = friends["email"] as! String
//My manager object has a custom array objects called contacts.
self.manager.index(withName: name, contact: edit)
self.tableView.reloadData();
} else {
print("Failed to Convert")
}
})
}
ContactManager 中的index(withName: String, contact: Contact) 方法:
//This method goes through the contactList to check names to see which contact has a specific name equal to "name", then it uses the "contact" to update that specific child.
public mutating func index(withName: String, contact: Contact) {
for iterator in 0 ..< contactList.count {
if (contactList[iterator].name == withName) {
contactList[iterator] = contact
}
}
}
【问题讨论】:
-
self.tableView.reloadData();应该在主线程中调用
标签: ios swift firebase firebase-realtime-database